Android 通过活动启动服务后完成活动

Android 通过活动启动服务后完成活动,android,service,Android,Service,我正在从onCreate()中的活动启动服务,然后在onStart()方法中完成该活动。当我运行应用程序时,它会显示一个对话框,上面写着“很遗憾,应用程序已停止”,但我的服务也会被调用,并按预期工作。我该怎么做才能不显示对话框 我的活动类别代码是: @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); Intent intent = ne

我正在从onCreate()中的活动启动服务,然后在onStart()方法中完成该活动。当我运行应用程序时,它会显示一个对话框,上面写着“很遗憾,应用程序已停止”,但我的服务也会被调用,并按预期工作。我该怎么做才能不显示对话框

我的活动类别代码是:

@Override
protected void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    Intent intent = new Intent(MainActivity.this, MyService.class);
    startService(intent);

}

@Override
protected void onStart(){

    MainActivity.this.finish();

}

尝试moveTaskToBack(true),然后在startService(…)行之后调用此.finish(),效果非常好。谢谢但是你能告诉我问题是什么,以及它是如何通过这个解决的吗@部门11