Reputation: 3657
I am working on a tablet application with two fragments on the main activity. The left fragment is a list fragment whose contents is updated when the user selects a tab or selects an item from 2 spinners within the ActionBar.
Originally I handled orientation change by overriding onConfigurationChanged. As this is not advised by Google and it causes issues with ActionBarSherlock, I have started work on doing it the right way. I have set my fragments to retain their instance (setRetainInstance) for orientation changes.
The problem is when the orientation changes the OnCreate method for the activity adds the tabs to the actionbar and selects one causing the list to reload. This also happens with the spinners as on rotation a new item is selected. On orientation change the list fragment has no need to refresh.
I know it is possible to save the tab and spinner state but how do I stop the list from updating as this is done in the onTabSelected and onItemSelected methods?
Upvotes: 2
Views: 1027
Reputation: 10672
How about using onRetainNonConfigurationInstance()
to save some state which should not change on orientation change? For example, if you follow @ThomasKJDK's answer , you could set the boolean
in this method. You could then retrieve this boolean
in onCreate()
; and decide on execution of various code segments based on this boolean
.
More details about this approach here.
Upvotes: 1
Reputation: 367
I don't know if this is the proper way of doing it, but you could make a local variable (boolean) which is set after the first OnCreate and reset at OnPause/OnDestroy. You can then use the created variable to exclude execution of some code segments in the onCreate method.
Upvotes: 1