我想创建一个服务,即使用户通过从运行进程菜单中将进程移出屏幕来关闭应用程序,该服务仍会执行后台作业。
我尝试的方法是通过像这样声明的方式在不同的进程中创建服务:
<service
android:name=".service.Service"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:process=":my_process" >
</service>
而 onStartCommand() 方法是:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
ContextWrapper cont = new ContextWrapper(getBaseContext()); cont.startService(service);
- JustADev