我在重新开始B之后从活动A-> B-> A开始旅行时遇到了一些麻烦。如何重新启动活动B而不会弄乱B完成后意图如何返回到A?
使用以下代码从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);
B完成并使用以下代码返回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();
}
这里是在A
中调用onActivity的地方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%的时间。重新启动时,它会返回错误。任何指导我正确方向的帮助将不胜感激。谢谢!
答案 0 :(得分:0)
尝试改变这个:
setContentView(R.layout.loadingscreen);
Intent i = getIntent();
finish();
startActivity(i);
到此:
setContentView(R.layout.loadingscreen);
Intent i = getIntent();
startActivity(i);
finish();