我见过许多android的例子,其中返回START_STICKY用于在引导时启动一个应用程序,但无论如何,我可以在IntentService上使用同样的例子。我理解服务方法作为一个单独的线程在主UI线程和IntentService上运行。
有人能帮我吗?
发布于 2014-07-02 17:38:15
在引导和START_STICKY中运行与彼此无关-- START_STICKY是一个标志,用于确定如果您的服务被Android杀死应该发生什么。
IntentService旨在处理传入意图(通过handleIntent),并在此之后立即停止。正如在source of IntentService中所看到的,它已经适当地处理了onStartCommand。
只要你要求
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />并在您的IntentService上设置正确的意图过滤器。
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>然后,您的服务将在启动完成时被调用。
(一个例外是,如果您的应用程序按照install location安装在SD卡上)
https://stackoverflow.com/questions/24537308
复制相似问题