Fix Notepadv3Solution orientation changes during NoteEdit
The current NoteEdit.java in Notepadv3Solution crashes on NPE when the screen orientation changes. This happens because a null Long is auto-unboxed to a long when used as an input to Bundle.putLong(String, long). The easiest solution is to use Bundle.putSerializable() instead. In addition duplicate notepad entries could result because mRowId was not necessarily defined when onSaveInstanceState(Bundle) was called. The solution to that is to call saveState() in that method. Fixes these buganizer bugs: Change-Id: Ice325f3b089867e4716deb48aefe8ec03f30ad55 http://b/issue?id=2266994 http://b/issue?id=2266962
This commit is contained in:
@@ -43,8 +43,8 @@ public class NoteEdit extends Activity {
|
|||||||
|
|
||||||
Button confirmButton = (Button) findViewById(R.id.confirm);
|
Button confirmButton = (Button) findViewById(R.id.confirm);
|
||||||
|
|
||||||
mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
|
mRowId = (savedInstanceState == null) ? null :
|
||||||
: null;
|
(Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
|
||||||
if (mRowId == null) {
|
if (mRowId == null) {
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
|
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
|
||||||
@@ -77,7 +77,8 @@ public class NoteEdit extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
|
saveState();
|
||||||
|
outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user