I am trying to implement orientation feature in the app. The app is basically made of tabs, using TabHost. Each tab is an activity group with a few activities. Each of this child activity runs a background task using AsyncTask to pull out server data and render the UI.
For instance,
HomeActivity- tab activity class that creates all the tabs
UserActivity- an activity group class representing a tab (say Tab 1)
TabOne- child activity inside UserActivity group
User sees Tab 1 soon after successful login. Issue begins when I tried to set orientation capabilities to this tab. Within the activity (TabOne), I added the following
@Override
public void onSaveInstanceState(Bundle outState) {
System.out.println("saving state..!");
outState.putStringArray("imageUrls", imageArray);
super.onSaveInstanceState(outState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
System.out.println("restoring state..!");
imageArray = savedInstanceState.getStringArray("imageUrls");
super.onRestoreInstanceState(savedInstanceState);
}
I am able to obtain 'imageUrls' state. But, later down, I could not access the static tab host variable.
HomeActivity.tabHost.getTabWidget().getChildAt(1)
tabHost variable is null! I am not saving any of its state. How could I possibly save tabHost instance?
While researching other community posts, I found 'onRetainNonConfigurationInstance()'. I implemented the same.
public Object onRetainNonConfigurationInstance() {
System.out.println("retaining state..!");
return HomeActivity.tabHost;
}
Bu this object is returned as null. Can anyone walk me through steps to handle orientation changes in apps with tabHost?
Ask me if you find anything confusing.
Thanks in advance!
SOLVED: Adding screenSize to activity tag in the manifest fixed the issue.
<activity android:name=".HomeActivity"
android:configChanges="orientation|screenSize"/>