1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Prevent NPEs in methods called by the handler after activity detached

This commit is contained in:
cketti 2012-11-15 21:42:10 +01:00
parent 4eefcb3a31
commit 999dd33169

View File

@ -450,6 +450,20 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
@Override
public void handleMessage(android.os.Message msg) {
// The following messages don't need an attached activity.
switch (msg.what) {
case ACTION_REMOTE_SEARCH_FINISHED: {
MessageListFragment.this.remoteSearchFinished();
return;
}
}
// Discard messages if the fragment isn't attached to an activity anymore.
Activity activity = getActivity();
if (activity == null) {
return;
}
switch (msg.what) {
case ACTION_FOLDER_LOADING: {
String folder = (String) msg.obj;
@ -466,10 +480,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
MessageListFragment.this.progress(progress);
break;
}
case ACTION_REMOTE_SEARCH_FINISHED: {
MessageListFragment.this.remoteSearchFinished();
break;
}
}
}
}