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

Fix a potential NullPointerException when rotating the device twice

When MessageListFragment is on the back stack and the device is rotated
the instance state will be restored but no new view will be created. If
the device is rotated again onSaveInstanceState() is called and we have
to take care not to assume that the views have been created.
This commit is contained in:
cketti 2013-02-05 16:01:07 +01:00
parent 0b04e526b4
commit 7f39b3c6d8

View File

@ -804,9 +804,9 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
saveSelectedMessages(outState); saveSelectedMessages(outState);
saveListState(outState);
outState.putBoolean(STATE_REMOTE_SEARCH_PERFORMED, mRemoteSearchPerformed); outState.putBoolean(STATE_REMOTE_SEARCH_PERFORMED, mRemoteSearchPerformed);
outState.putParcelable(STATE_MESSAGE_LIST, mListView.onSaveInstanceState());
outState.putParcelable(STATE_ACTIVE_MESSAGE, mActiveMessage); outState.putParcelable(STATE_ACTIVE_MESSAGE, mActiveMessage);
} }
@ -849,6 +849,15 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
} }
private void saveListState(Bundle outState) {
if (mSavedListState != null) {
// The previously saved state was never restored, so just use that.
outState.putParcelable(STATE_MESSAGE_LIST, mSavedListState);
} else if (mListView != null) {
outState.putParcelable(STATE_MESSAGE_LIST, mListView.onSaveInstanceState());
}
}
private void initializeSortSettings() { private void initializeSortSettings() {
if (mSingleAccountMode) { if (mSingleAccountMode) {
mSortType = mAccount.getSortType(); mSortType = mAccount.getSortType();