brian
brian

Reputation: 6912

tabhost reload while screen orientation change

I use tabhost as my main activity. And show the first list in initial. And onclick to the second list. At this time, the screen orientation change, the screen is change to initial list. How to resolve it? I already try below: 1. add android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait" in Manifest 2. add onConfigurationChanged in each activity

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

Is there any other solution?

Sorry~ I means the content in tabcontent(FrameLayout). And the tabs(TabWidget) didn't reload when the screen change.

On create, call AActivity to show list1. And in AActivity listonclick, I make it call BActivity to show list2. But when screen change, the tabcontent call AActivity and show list1.

Upvotes: 1

Views: 1165

Answers (2)

Squonk
Squonk

Reputation: 48871

If I understand correctly, you need to save which Tab is selected. You could try something like this...

public class MyTabActivity extends TabActivity
    implements TabHost.onTabChangeListener {

    private int currentTab = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        getTabHost().setOnTabChangedListener(this);
    }

    @Override
    protected void onResume() {
        ...
        currentTab = getSharedPreferences("myapp", MODE_PRIVATE).getInt("currentTab", 0);
        getTabHost().setCurrentTab(currentTab);
    }

    @Override
    protected void onPause() {
        ...
        getSharedPreferences("myapp", MODE_PRIVATE).edit().putInt("currentTab", currentTab).commit();
    }

    @Override
    public void onTabChanged(String tabId) {
        currentTab = getTabHost().getCurrentTab();
    }
}

Upvotes: 2

Ring
Ring

Reputation: 2309

onCreate is called on your activity again when the screen's orientation changes. Maybe you are setting to the "initial list" in your onCreate activity.

Upvotes: 1

Related Questions