summaryrefslogtreecommitdiffstats
path: root/tutorials
diff options
context:
space:
mode:
authorTom O'Neill <tomo@google.com>2009-12-11 16:01:04 -0800
committerTom O'Neill <tomo@google.com>2009-12-11 16:03:52 -0800
commit7c21d1cd4051a7aaab5c15d63649315708c6aaa4 (patch)
treef1738ae1e528cc5d88bba2e2777562349137d239 /tutorials
parentd0225ee63f305ef59e17f8ad0dc16b2ef5e85af0 (diff)
downloadandroid_development-7c21d1cd4051a7aaab5c15d63649315708c6aaa4.tar.gz
android_development-7c21d1cd4051a7aaab5c15d63649315708c6aaa4.tar.bz2
android_development-7c21d1cd4051a7aaab5c15d63649315708c6aaa4.zip
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
Diffstat (limited to 'tutorials')
-rwxr-xr-xtutorials/NotepadCodeLab/Notepadv3Solution/src/com/android/demo/notepad3/NoteEdit.java7
1 files changed, 4 insertions, 3 deletions
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