0
我在B重新啓動後從活動A-> B-> A出差旅行時遇到問題。如何重新開始活動B而不會搞亂B完成後如何將意圖返回給A?活動在重新啓動後不會返回數據
B從一個稱爲與此代碼:
public void activityFunction(Context gameContext){
//This function was made to pass the player class back and forth between
setContentView(R.layout.loadingscreen);
Intent i = new Intent(gameContext, gamePanel.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(i,1);
}
在B的遊戲活動與此代碼復位:
setContentView(R.layout.loadingscreen);
Intent i = getIntent();
finish();
startActivity(i);
乙完成並返回到A中進行這樣的代碼:
public void levelOver(){
setContentView(R.layout.loadingscreen);
Intent resultIntent = new Intent();
resultHolder results = new resultHolder(playerStats);
resultIntent.putExtra(.......);
resultIntent.putExtra(.......);
resultIntent.putExtra(.......);
resultIntent.putExtra(.......);
setResult(Activity.RESULT_OK, resultIntent);
finish();
}
這裏是在哪裏onActivity被稱爲A
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (1) : {
if (resultCode == Activity.RESULT_OK) {
returnedWithResults = true;
new AsyncReturnGameData().execute(data);
}
break;
}
}
}
只要未重新啓動,活動B就會返回100%的時間。當它重新啓動時,它會返回一個錯誤。任何幫助指引我在正確的方向將不勝感激。謝謝!
抱歉耽擱。這是正確的答案 – HarshMarshmallow