Issue
I see a lot of examples of Android code setting interfaces inside the onStart(); method and clearing them with null inside onStop();
For example:
@Overrride
public void onStart(){
button.setOnClickListener(this);
}
@Override
public void onStop(){
button.setOnClickListener(null);
}
Why is this? Is this good coding practice?
Solution
An Object becomes eligible for garbage collection only when no active(non-daemon) Threads has reference to the Object.While the lifecycle of android.app.Activity would theoretically complete after invoking the onDestroy() method ,it still needs to be dereferenced from any object which may be holding a reference to it.Therefore,the above code tries to remove its own reference from Button object so that it may become eligible for garbage collection.
Answered By - Kumar Abhinav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.