android - Service被kill掉了,进程还能活着吗?

标签 android

我的应用有服务和 Activity 。

假设我的应用进程正在运行。一段时间后,由于内存不足,Android 操作系统终止了我应用程序中的服务。我的问题是,Android 是否有可能只终止服务并使进程保持 Activity 状态?或者当服务被杀死时,进程也必须被杀死?

谢谢。

最佳答案

我对此有 99.9% 的把握:如果服务顺利进行,流程也会进行。终止服务的条件非常苛刻,例如在内存不足的情况下。我自己的经验是,当服务终止时,整个应用程序都被终止了。服务和流程是联系在一起的。是的,您可以在不终止进程的情况下手动停止您的服务,但我几乎可以肯定,当操作系统因内存不足而终止您的服务时,然后再见进程。

查看 Hackbod 的回答和评论:Android service killed

参见 http://developer.android.com/reference/android/app/Service.html和 onLowMemory:

This is called when the overall system is running low on memory, and would like actively running process to try to tighten their belt. While the exact point at which this will be called is not defined, generally it will happen around the time all background process have been killed, that is before reaching the point of killing processes hosting service and foreground UI that we would like to avoid killing.

背景信息:http://about-android.blogspot.com/2010/07/lifecycle-of-android-application.html

这也很有趣:Will we leak the android service connection if the client's process is killed by android?

关于android - Service被kill掉了,进程还能活着吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8087596/

相关文章:

java - 从回调运行计时器时不调用 Looper.prepare()

android - 通过适配器外部的 Activity 计算数据库中的行数

android - 如何以正确的方式将 jwt 存储在 android 应用程序中?

java - LG G3 手机的 Android 6.0 HTTPClient 问题

android - 重命名 Play 商店应用程序

java - 子句 IN Realm Java

android - 如何改变android中单选按钮的颜色?

android - 我们如何在 google glass 上启用 Debug模式以在 google glass 上测试 android 应用程序?

Android @Override 错误

android - 我的 android 应用程序可以从内置的电话调用日志应用程序启动吗?