我有两个活动A和B. 在A中有一个按钮BTN:
Intent myIntent = new Intent(A.this, B.class);
startActivityForResult(myIntent, B_VIEW);
问题在于,如果B.onDestroy()
由先前的finish()
(步骤2)引起,尚未执行,则会立即执行,因此B关闭: - (
我想要那个,如果还没有执行,如果我重新打开B,那么B.finish()不会开火吗?
答案 0 :(得分:0)
你最好重新开始处理这种过程。
最好的办法是将密钥数据打包到onSaveInstanceState
中的捆绑包中,然后检查onCreate(Bundle)
函数中是否存在该捆绑包。这样的事情可以起作用(Largely copied from the Android Docs):
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
public void onCreate(Bundle savedInstanceState)
{
if (savedInstanceState==null)
{ //This is the first time starting
mCurrentScore=0;
mCurrentLevel=1;
}
else
{
mCurrentScore=savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel=savedInstanceState.getInt(STATE_Level);
}
}