问题
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!
回答1:
Question: Will this cause it to leak the service connection?
The ServiceConnection
object would be in the process of "X" and therefore will go away when that process is terminated.
来源:https://stackoverflow.com/questions/7633317/will-we-leak-the-android-service-connection-if-the-clients-process-is-killed-by