OSDN Git Service

Fix occasional crash when restoring photo page state
authorBobby Georgescu <georgescu@google.com>
Mon, 24 Sep 2012 18:26:10 +0000 (11:26 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Mon, 24 Sep 2012 21:29:54 +0000 (14:29 -0700)
Bug: 7216012
If the saved state being used to restore the photo page
includes an out-of-bounds index, ignore it and reset the
index to 0.

Change-Id: I1b8aa82cbc553297189abb57bd274d7eb53f61e0

src/com/android/gallery3d/app/PhotoPage.java

index c5c77e1..b173620 100644 (file)
@@ -353,10 +353,13 @@ public class PhotoPage extends ActivityState implements
                 Log.w(TAG, "failed to restore " + mSetPathString);
             }
             if (itemPath == null) {
-                if (mMediaSet.getMediaItemCount() > 0) {
+                int mediaItemCount = mMediaSet.getMediaItemCount();
+                if (mediaItemCount > 0) {
+                    if (mCurrentIndex >= mediaItemCount) mCurrentIndex = 0;
                     itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1)
                         .get(0).getPath();
                 } else {
+                    // Bail out, PhotoPage can't load on an empty album
                     return;
                 }
             }