终止单独的流程服务后,将其重新启动,而不将其绑定到应用程序的主流程

时间:2018-12-19 09:09:16

标签: android service

我想知道是否有任何方法可以在一个单独的进程服务被终止(或崩溃)时重新启动,而不将其绑定到应用程序的主进程(我希望该服务即使在应用程序的主进程为由于任何原因被杀死)。

当前,该服务由系统通过AndroidManifest启动:

<service
    android:name=".services.MySeparatedProcessService"
    android:exported="true"
    android:label="SeparatedProcessService"
    android:process=":separatedProcess"
    android:stopWithTask="false">
    <intent-filter>
        <action android:name="android.service.notification.MySeparatedProcessService" />
    </intent-filter>
</service>

问题在于,当系统启动它时,调用了以下回调:

public int onStartCommand(Intent intent, int flags, int startId)

所以我无法返回START_STICKY

1 个答案:

答案 0 :(得分:0)

您可以混合使用广播接收器和未完成的意图来完成此任务。

这是一个链接,它需要进行位置更新,尤其是对于oreo设备。

background-location-updates-android-o