문제

Application has a tabhost managed through TabActivity. It has option to add tabs at runtime.

Say 5 tabs are added in runtime and different activities are shown.

When I rotate the screen the activity undergoes the cycle o destroy and create. I want to maintain the tabs added by user in runtime to be available during this cycle.

도움이 되었습니까?

해결책

The easiest way to do this is to change your Manifest to say that you will handle the orientation change yourself.

<activity
        android:name=".MyActivity"
        android:configChanges="orientation" />

What this does is tell the system to not recreate the activity on orientation change. You can then override OnOrientationChanged to modify any configuration changes.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    //put configuration changes here
}

You can also leave it out if you don't need any explicit changes.

For further reading: Android Runtime Changes

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top