Java 在服务电话中没有任何事情发生

Java 在服务电话中没有任何事情发生,java,android,xml,service,android-manifest,Java,Android,Xml,Service,Android Manifest,我创建了一个新的简单项目(在AndroidStudio 0.8.2上)来测试这项服务,但不确定为什么它不起作用 MyActivity.java import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class My

我创建了一个新的简单项目(在AndroidStudio 0.8.2上)来测试这项服务,但不确定为什么它不起作用

MyActivity.java

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MyActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    startService(new Intent(this, TestService.class));
}
TestService.java

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class TestService extends Service {
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    // do something when the service is created
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    super.onStartCommand(intent, flags, startId);

    return START_REDELIVER_INTENT;
}
}
我还添加了AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"     
package="..." >         
<application         ...     
</application>     
<service         
android:name=".TestService">
</service> 
</manifest>

您已经在
元素之外声明了
。它应该和你的其他部件一起放进去:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="..." >         
    <application     
        <service         
            android:name=".TestService">
        </service> 
        ...
    </application>     
</manifest>


在我的机器上似乎工作得很好。清单中服务的
android:name
是否正确?如果没有,启动会自动失败(Logcat中不会弹出任何内容)。是的。。。它就在那里
谢谢^ ^不,它没有,应用程序继续运行,我想知道为什么在onStartCommand上放置断点后,服务从未被调用。