在我的Android应用中,我通过调用IntentService来自Activity启动。
startService(new Intent(this, MyService.class));
而且它的工作效果非常好。我可以在活动之间移动,按Home按钮切换到其他应用程序......它仍然在工作。但是如果我从最近使用屏幕中删除我的应用程序,则我的服务将停止。我该如何避免这种情况?换句话说,即使我的应用程序从最近使用的应用程序中关闭,我该如何让我的服务保持运行状态?
我的服务代码如下:
public class MyService extends IntentService {
public MyService() {
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
//Here I run a loop which takes some time to finish
}
}