可能重复:
强制停止后如何保持服务运行?
嗨,这是我用来创建服务的一段代码。尝试在设置-> 管理应用程序-> 运行服务中手动停止该服务,即使在 Returning-Sticky .... 之后服务也不会重新启动。请帮忙。任何帮助将不胜感激
代码是:
public class MyService extends Service {
private static final String TAG = "MyService";
@Override
public void onCreate() {
Toast.makeText(this, "My Service Created", 0).show();
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", 0).show();
Log.v(TAG, "onDestroy");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "On Start Command - service started", 0).show();
Log.v(TAG, "onStart");
**return START_STICKY;**
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
请帮忙..