Code example for ViewPager

Methods: getAdaptergetCurrentItemonSaveInstanceState

		super(context, attrs);
	public Parcelable onSaveInstanceState() {
		Parcelable superState = super.onSaveInstanceState();
		Bundle b = new Bundle();
		b.putParcelable(STATE_SUPER, superState);
		if (getAdapter() != null) { 
			int item = this.getCurrentItem();
			try { 
				b.putInt(STATE_POS, getVPAdapter().getRealPage(item));
			} catch (ArrayIndexOutOfBoundsException ex) {
				// occurs very rarely when something triggers a future backstack pop while the activity is hidden 
				// this is because the adapter has not gotten a chance to construct its mapping yet 
				// it is not necessary to save this information in this case 
				// ignore the error and move on 
		return b;
Contextual code suggestions in your IDE  Get Codota for Java