Buggy code:
public class GalleryActivity extends TrackedActivity implements GalleryProviderListener , GalleryView . Listener , Slider . OnSetProgressListener { public static final String ACTION_DIR = "dir" ; public static final String ACTION_ZIP = "zip" ; public static final String ACTION_EH = "eh" ; public static final String KEY_ACTION = "action" ; public static final String KEY_FILENAME = "filename" ; public static final String KEY_GALLERY_INFO = "gallery_info" ; public static final String KEY_PAGE = "page" ; public static final String KEY_SHOWING = "showing" ; private static final long SLIDER_ANIMATION_DURING = 150 ; private static final long HIDE_SLIDER_DELAY = 3000 ; private String mAction ; private String mFilename ; private GalleryInfo mGalleryInfo ; private int mPage ; @ Nullable private GalleryView mGalleryView ; @ Nullable private Uploader mUploader ; @ Nullable private GalleryProvider mGalleryProvider ; @ Nullable private SystemUiHelper mSystemUiHelper ; private boolean mSystemUiShowing = false ; @ Nullable private View mClock ; @ Nullable private View mBattery ; @ Nullable private View mSliderPanel ; @ Nullable private TextView mLeftText ; @ Nullable private TextView mRightText ; @ Nullable private Slider mSlider ; private int mLayoutMode ; private int mSize ; private int mCurrentIndex ; private final ConcurrentPool < GalleryActivity . NotifyTask > mNotifyTaskPool = new ConcurrentPool ( 3 ) ; private final Runnable mRequestLayoutSliderTask = new Runnable ( ) { @ Override public void run ( ) { } } ; private final SimpleAnimatorListener mHideSliderListener = new SimpleAnimatorListener ( ) { @ Override public void onAnimationEnd ( Animator animation ) { } } ; private final Runnable mHideSliderRunnable = new Runnable ( ) { @ Override public void run ( ) { } } ; private void buildProvider ( ) { } private void onInit ( ) { } private void onRestore ( @ NonNull Bundle savedInstanceState ) { mAction = savedInstanceState . getString ( GalleryActivity . KEY_ACTION ) ; mFilename = savedInstanceState . getString ( GalleryActivity . KEY_FILENAME ) ; mGalleryInfo = savedInstanceState . getParcelable ( GalleryActivity . KEY_GALLERY_INFO ) ; <START_BUG> mPage = savedInstanceState . getInt ( GalleryActivity . KEY_ACTION , ( - 1 ) ) ; <END_BUG> buildProvider ( ) ; } @ Override protected void onSaveInstanceState ( Bundle outState ) { } @ Override protected void onCreate ( @ Nullable Bundle savedInstanceState ) { } @ Override protected void onDestroy ( ) { } @ Override protected void onPause ( ) { } @ Override protected void onResume ( ) { } @ Override public void onWindowFocusChanged ( boolean hasFocus ) { } @ Override public boolean onKeyDown ( int keyCode , KeyEvent event ) { } @ Override public boolean onKeyUp ( int keyCode , KeyEvent event ) { } private GalleryPageView findPageByIndex ( int index ) { } @ SuppressLint ( "SetTextI18n" ) private void updateSlider ( ) { } @ Override public void onDataChanged ( ) { } @ Override public void onPageWait ( int index ) { } @ Override public void onPagePercent ( int index , float percent ) { } @ Override public void onPageSucceed ( int index , Image image ) { } @ Override public void onPageFailed ( int index , String error ) { } @ Override public void onDataChanged ( int index ) { } @ Override public void onSetProgress ( Slider slider , int newProgress , int oldProgress , boolean byUser , boolean confirm ) { } @ Override public void onFingerDown ( ) { } @ Override public void onFingerUp ( ) { } @ Override public void onUpdateCurrentIndex ( int index ) { } @ Override public void onTapSliderArea ( ) { } @ Override public void onTapMenuArea ( ) { } @ Override public void onLongPressPage ( int index ) { } private void showSlider ( View sliderPanel ) { } private void hideSlider ( View sliderPanel ) { } private class GalleryMenuHelper implements DialogInterface . OnClickListener { private final View mView ; private final Spinner mReadingDirection ; private final Spinner mScaleMode ; private final Spinner mStartPosition ; private final SwitchCompat mKeepScreenOn ; private final SwitchCompat mShowClock ; private final SwitchCompat mShowBattery ; private final SwitchCompat mVolumePage ; @ SuppressLint ( "InflateParams" ) public GalleryMenuHelper ( ) { } public View getView ( ) { } @ Override public void onClick ( DialogInterface dialog , int which ) { } } private void shareImage ( int page ) { } private void saveImage ( int page ) { } private void showPageDialog ( final int page ) { } private class NotifyTask implements Runnable { public static final int KEY_LAYOUT_MODE = 0 ; public static final int KEY_SIZE = 1 ; public static final int KEY_CURRENT_INDEX = 2 ; public static final int KEY_TAP_SLIDER_AREA = 3 ; public static final int KEY_TAP_MENU_AREA = 4 ; public static final int KEY_LONG_PRESS_PAGE = 5 ; private int mKey ; private int mValue ; public void setData ( int key , int value ) { } private void onTapMenuArea ( ) { } private void onTapSliderArea ( ) { } private void onLongPressPage ( final int index ) { } @ Override public void run ( ) { } } private class GalleryAdapter extends GalleryView . Adapter { @ Override public String getError ( ) { } @ Override public int size ( ) { } @ Override public void onBind ( GalleryPageView view , int index ) { } @ Override public void onUnbind ( GalleryPageView view , int index ) { } } }

Fix:
mPage = savedInstanceState . getInt ( GalleryActivity . KEY_PAGE , ( - 1 ) ) ;