Follow on from a previous question
One first screen activity I am clicking a button and doing this
Intent intent = new Intent(MainMenu.this, NewClass.class);
intent.putExtra("value1", value1);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Value is passed to new activity and is used in the onCreate()-method
On new Activity I am saving the state when I click back button
@Override
protected void onSaveInstanceState(Bundle outState) {
// the UI component values are saved here.
super.onSaveInstanceState(outState);
Toast.makeText(this, "Activity state saved", Toast.LENGTH_LONG).show();
}
@Override
public void onBackPressed() {
//super.onBackPressed();
Intent intent = new Intent(RoundScoring.this, MainMenu.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
Toast.makeText(this, "Back Button Pressed", Toast.LENGTH_LONG).show();
}
On the first screen again I am clicking a different button with the following :
Intent intentContiune = new Intent(MainMenu.this, NewClass.class);
intentContiune.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intentContiune);
The Activty is loaded but always fails as the value has not been set. I wrote a onRestorInstanceState to re-populate the value from the bundle but it is never fired. Can someone say what I am doing wrong
Thanks for your time
UPDATE
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.d(DEBUG_TAG, "returnstate called");
super.onRestoreInstanceState(savedInstanceState);
value = savedInstanceState.getString("value");
}
Use Application
yourApplication.javaAndroidManifest.xmlNow You can save value anywhere using:
SAVE
LOAD