0

I am using action bar fragment in my app.When screen rotates contents of action bar lost please suggest how to retain them. Here is the code i am doing for that

@Override
protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if(currentDisplayedCase != null) {
            outState.putInt(DISPLAY_CASE_KEY, currentDisplayedCase.intValue());

        }
        outState.putString(ACTION_BAR_TEXT, textView1.getText().toString());
    }

and in onCreate method

if(savedInstanceState!=null&&savedInstanceState.containsKey(ACTION_BAR_TEXT))
        textView1.setText(savedInstanceState.getString(ACTION_BAR_TEXT, null));
Supreet
  • 2,451
  • 8
  • 25
  • 42

2 Answers2

0

When device is rotated, the activity is restarted.

For proper solution you can see following link

Losing data when rotate screen

It will help you understand why your data is lost and how to recover it.

Community
  • 1
  • 1
genius
  • 37
  • 6
0

you need to add following in your activity declaration in manifest file android:configChanges="orientation", i. e.

<activity android:name=".myActivity" android:configChanges="orientation" android:label="@string/txt_app_name" android:theme="@style/myTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

this means that you will be handling orientation changes in your activity.

Anirudh
  • 13
  • 3