杀死活动进程时服务重新启动

时间:2013-05-10 05:16:42

标签: android android-service

我有一项活动,可以通过我服务的android:process属性在单独的流程中启动服务。

我的服务onStartCommand()函数返回START_STICkY

我通过最近的应用按钮轻扫我的活动过程,服务流程重新启动。

我想知道在活动进程被终止时是否有办法让服务保持运行。

1 个答案:

答案 0 :(得分:0)

I want to know if there is a way to keep the service running when the activity process is killed.

不,没有办法让服务继续运行。因为,

Closed by the user via the Running Services screen in Settings.

Closed by the user via a task killer.

Closed by Android to free up memory in times of need.

Keep the service running is BAD idea.

但你可以做到,

- >您可以使用 BROADCAST RECEIVER 重启您的服务。(来电时,BOOT完成,收到短信..等等,根据您的要求使用)