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.
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.
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With