我有一个 Activity 通过我服务的 android:process
属性在单独的进程中启动服务。
我的服务的 onStartCommand()
函数返回 START_STICkY
。
我通过最近使用的应用程序按钮将其滑开,然后服务进程重新启动,从而终止了我的 Activity 进程。
我想知道是否有办法在 Activity 进程被杀死时保持服务运行。
最佳答案
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 重新启动您的服务。(当来电、启动完成、收到短信等时,根据您的要求使用它)
关于android - 杀死 Activity 进程时服务重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16475634/