从以前的问题,请遵循onRestoreInstanceState不会被调用
一个第一屏幕上的活动,我点击一个按钮,这样
Intent intent = new Intent(MainMenu.this, NewClass.class);
intent.putExtra("value1", value1);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
值传递给新的活动,并在onCreate()
- 方法是使用
在新的活动,我节电状态,当我点击后退按钮
@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();
}
在第一个屏幕我再次点击不同的按钮具有以下:
Intent intentContiune = new Intent(MainMenu.this, NewClass.class);
intentContiune.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intentContiune);
的Activty被加载但作为价值尚未设置总是失败。我写了一个onRestorInstanceState
来重新从包中填充值,但它永远不会被解雇。有人会说我在做什么错
感谢您的时间
UPDATE
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.d(DEBUG_TAG, "returnstate called");
super.onRestoreInstanceState(savedInstanceState);
value = savedInstanceState.getString("value");
}
SQLite数据库,但仍旧没有 –
对不起,我编辑的问题: –
但onResume不能与捆绑一起使用。正如你所看到的,我正在节省一笔价值 –