我的应用有服务和 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/