Issue
I have a service helper singelton, which basically connects an Activity to a Service (sends requests and receives broadcasts and provides a callback interface for the Activity to implement)
The reccomended way is probably to do it onResume() / onPause() like this:
MyActivity extends Activity implements ServiceHelper.Callbacks {
protected void onResume() {
super.onResume();
mServiceHelper.setListener(this);
}
protected void onPause() {
super.onPause();
// Avoid leaking this Activity
mServiceHelper.setListener(null);
}
}
This prevents the leaks, but in thas way the Activity might miss some important callbacks while paused / not visible. Ideally I would do it in onCreate() and onDestroy(), but its stated that the Activity is killable after onPause() so the Activity might get leaked (if I interpret this correctly)
What is the right way to do this?
Solution
onCreate/onDestroy pair is the right one. If the application is getting killed by the system all memory is released so it's not possible to have leaks in that case.
Answered By - azertiti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.