android - 杀死 Activity 进程时服务重新启动

标签 android android-service

我有一个 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/

相关文章:

android - 在哪里创建自己的线程,内部服务类或我们调用服务的 Activity 表单内部

java - Java 中所有回调实现的相同代码

android - 如何在由 AlarmManager 计划启动的服务中检索 Intent Extras?

android - 通过使用通知操作按钮以编程方式在 android 通知的大 View 和普通 View 之间切换

android - 为什么我的 ViewPager 这么慢?

android - 我如何调试 android 服务 - 扩展服务类的 Activity -

android - 什么类型的后台服务?

android - 从 fragment 中显示 TimePickerDialog

android - 无法点击 Android Lollipop 上的 webview 链接

java - 条形码扫描仪使用 ML Kit 仅读取 QR 码