如果客户端进程被android杀死,我们会泄漏android服务连接吗?
条件: 我有一个远程服务(使用 AIDL)的客户端活动“X”,它调用 onCreate()
和 unbindService()
中的 bindService()
onDestroy()
中的 code>。假设此 Activity 已启动但不在前台(已发生 onStop()
)。
据说,当android系统在其他地方需要更多内存时,它可能会杀死另一个优先级较低的活动(可能是“X”)的进程。
如果说,Android 系统决定杀死“X”的进程,根据活动生命周期图,如果在需要更多内存时杀死该进程,则不会调用 onDestroy()
。 http://developer.android.com/guide/topics/fundamentals/activities.html
问题: 这会导致服务连接泄漏吗?那么在 onStart()
和 onStop()
中绑定和取消绑定服务更安全吗?
提前致谢!
Condition:
I have a client activity "X" of a remote service (with AIDL) that calls the bindService()
in the onCreate()
and unbindService()
in the onDestroy()
. Assume that this activity has been started but not in the foreground (onStop()
has happened).
It is said that when android system needs more memory elsewhere it might kill the process of another activity with less priority (possibly "X").
If, says, the android system decides to kill "X"'s process, according to the activity-lifecycle diagram the onDestroy()
will not be called if the process is killed when more memory is needed.
http://developer.android.com/guide/topics/fundamentals/activities.html
Question:
Will this cause it to leak the service connection? Is it safer then to bind and unbind service in onStart()
and onStop()
?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ServiceConnection
对象将位于“X”进程中,因此当该进程终止时该对象将消失。The
ServiceConnection
object would be in the process of "X" and therefore will go away when that process is terminated.