应用程序管理器中终止后自动重启服务

时间:2014-02-08 12:05:24

标签: android service

我正在尝试在一个单独的进程中创建一个服务,该进程应在​​任务管理器中手动停止后重新启动。在onStartCommand()中返回START_STICKY对我不起作用。这是代码:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

Activity会像这样启动服务:

@Override
protected void onResume() {
    doStartService();

    super.onResume();
}

private void doStartService() {
    Intent intent = new Intent(getApplicationContext(), MyService.class);
    startService(intent);
    doBindService();
}

private void doBindService() {
    bindService(new Intent(this, MyService.class), mConnection, Context.BIND_AUTO_CREATE);
    mBound = true;
}

有什么不对?

0 个答案:

没有答案
相关问题