Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when i change the orientation from portrait to landscape my calculated result is disappearing. how to resolve it?

Hai, in my calculator app when i click on calculate button result is appearing normally, but when i change the orientation calculated result is disappearing.

like image 792
MUKTHA Avatar asked Apr 11 '11 08:04

MUKTHA


2 Answers

Try this code

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

and in the manifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">´
    <activity android:name="XXXXX"
              android:label="@string/app_name"
              android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> //this <--
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    ...
</application>

EDIT: I added the screenSize flag. In android >3 if you dont add this flag the method onConfigurationChanged will not be called.

like image 109
Aracem Avatar answered Sep 29 '22 11:09

Aracem


Please see this example on how to save the state of your Activity using a Bundle. First you have to override the onSaveInstanceState method.

public void onSaveInstanceState(Bundle savedInstanceState) {
    TextView  txtName = (TextView)findViewById(R.id.raj44);
    String  aString = txtName.getText().toString();
    savedInstanceState.putString("Name", aString);
    super.onSaveInstanceState(savedInstanceState);
} 

In the onCreate method you can then restore the state of your instance from the saved Bundle.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.concretetool);
    if (savedInstanceState != null) {
        String  aString = savedInstanceState.getString("Name");
        if (aString != null) {
            txtName = (TextView)findViewById(R.id.raj44);
            txtName.setText(aString);
        }
    }
}
like image 43
Narasimha Avatar answered Sep 29 '22 13:09

Narasimha