From 7c21d1cd4051a7aaab5c15d63649315708c6aaa4 Mon Sep 17 00:00:00 2001 From: Tom O'Neill Date: Fri, 11 Dec 2009 16:01:04 -0800 Subject: 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 --- .../Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tutorials/NotepadCodeLab') diff --git a/tutorials/NotepadCodeLab/Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java b/tutorials/NotepadCodeLab/Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java index 710ea339d..f5eb6c433 100755 --- a/tutorials/NotepadCodeLab/Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java +++ b/tutorials/NotepadCodeLab/Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java @@ -43,8 +43,8 @@ public class NoteEdit extends Activity { Button confirmButton = (Button) findViewById(R.id.confirm); - mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID) - : null; + mRowId = (savedInstanceState == null) ? null : + (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID); if (mRowId == null) { Bundle extras = getIntent().getExtras(); mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) @@ -77,7 +77,8 @@ public class NoteEdit extends Activity { @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putLong(NotesDbAdapter.KEY_ROWID, mRowId); + saveState(); + outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId); } @Override -- cgit v1.2.3