Android ViewPager setCurrentItem not working after onResume

i can’t really answer WHY exactly this happens, but if you delay the setCurrentItem call for a few milliseconds it should work. My guess is that because during onResume there hasn’t been a rendering pass yet, and the ViewPager needs one or something like that. private ViewPager viewPager; @Override public void onResume() { final int … Read more

Android – save/restore fragment state

When a fragment is moved to the backstack, it isn’t destroyed. All the instance variables remain there. So this is the place to save your data. In onActivityCreated you check the following conditions: Is the bundle != null? If yes, that’s where the data is saved (probably orientation change). Is there data saved in instance … Read more

Android activity life cycle – what are all these methods for?

See it in Activity Lifecycle (at Android Developers). onCreate(): Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity’s previously frozen state, if there was one. Always … Read more