Buggy code:
public class MainActivity extends ActionBarActivity { LinearLayout mainlayout ; static boolean isVisible = false ; public static boolean getIsVisible ( ) { } Fragment fragment ; SharedPreferences preferences = null ; final String currentTab = "currentTab" ; public static final String SHOWMESSAGE_ACTION = "com.kivSW.phonerecorderui.MainActivity.SHOWMESSAGE_ACTION" ; public static final String EMAIL_RECEIVING_STARTED_ACTION = "com.kivSW.phonerecorderui.MainActivity.SHOWSTATUS_ACTION" ; public static final String EMAIL_RECEIVING_FINISHED_ACTION = "com.kivSW.phonerecorderui.MainActivity.EMAIL_RECEIVING_FINISHED_ACTION" ; public static final String OPEN_ACTION = "com.kivSW.phonerecorderui.MainActivity.OPEN" ; ViewPager pager ; protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; setContentView ( mainactivity ) ; <START_BUG> preferences = getSharedPreferences ( "ini" , MODE_PRIVATE ) ; <END_BUG> pager = ( ( ViewPager ) ( findViewById ( R . id . pager ) ) ) ; pager . setAdapter ( new MainActivity . PageAdapter ( getSupportFragmentManager ( ) ) ) ; pager . setOnPageChangeListener ( new ViewPager . OnPageChangeListener ( ) { @ Override public void onPageSelected ( int ind ) { getSupportActionBar ( ) . setSelectedNavigationItem ( ind ) ; } @ Override public void onPageScrolled ( int arg0 , float arg1 , int arg2 ) { } @ Override public void onPageScrollStateChanged ( int arg0 ) { } } ) ; ActionBar ab = getSupportActionBar ( ) ; ab . setNavigationMode ( NAVIGATION_MODE_TABS ) ; ActionBar . TabListener tabListener = new ActionBar . TabListener ( ) { public void onTabSelected ( ActionBar . Tab tab , FragmentTransaction ft ) { pager . setCurrentItem ( tab . getPosition ( ) ) ; MainActivity . PageAdapter pa = ( ( MainActivity . PageAdapter ) ( pager . getAdapter ( ) ) ) ; PageFragment pf = ( ( PageFragment ) ( pa . getItem ( tab . getPosition ( ) ) ) ) ; pf . onSelect ( ) ; } @ Override public void onTabReselected ( Tab arg0 , FragmentTransaction arg1 ) { } @ Override public void onTabUnselected ( Tab tab , FragmentTransaction ft ) { pager . setCurrentItem ( tab . getPosition ( ) ) ; MainActivity . PageAdapter pa = ( ( MainActivity . PageAdapter ) ( pager . getAdapter ( ) ) ) ; PageFragment pf = ( ( PageFragment ) ( pa . getItem ( tab . getPosition ( ) ) ) ) ; pf . onUnselect ( ) ; } } ; ActionBar . Tab tab ; tab = ab . newTab ( ) ; tab . setIcon ( gearwheeltab ) ; tab . setTabListener ( tabListener ) ; ab . addTab ( tab ) ; tab = ab . newTab ( ) ; tab . setIcon ( playtab ) ; tab . setTabListener ( tabListener ) ; ab . addTab ( tab ) ; int pos = preferences . getInt ( currentTab , 0 ) ; if ( ( pos < 0 ) || ( pos >= ( ab . getNavigationItemCount ( ) ) ) ) pos = 0 ; ab . setSelectedNavigationItem ( pos ) ; onNewIntent ( getIntent ( ) ) ; BlueToothService . checkService ( this ) ; } @ Override protected void onNewIntent ( Intent intent ) { } @ Override public void onRestart ( ) { } @ Override public void onStart ( ) { } @ Override public void onStop ( ) { } protected void onSaveInstanceState ( Bundle outState ) { } void onEmailReceivingIsStarted ( String msg ) { } void onEmailReceivingIsFinished ( ) { } private class PageAdapter extends FragmentPagerAdapter { Fragment [ ] pages ; public PageAdapter ( FragmentManager fm ) { } @ Override public Fragment getItem ( int ind ) { } @ Override public int getCount ( ) { } } public static void showActivity ( Context context ) { } public static void showMessage ( Context context , String title , String message ) { } public static void onStartEmailReceiving ( Context context , String msg ) { } public static void onFinishEmailReceiving ( Context context ) { } }

Fix:
preferences = getApplicationContext ( ) . getSharedPreferences ( "ini" , MODE_PRIVATE ) ;