Code example for ViewPager

Methods: getAdapter, getCurrentItem, onSaveInstanceState

0
		super(context, attrs);
	} 
 
	@Override 
	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;
	}