所以我实施了双按以退出我的主动,如果我去设置活动或游戏活动,退出就会很好。但是,如果我去主动 - > gameactivity - > gameoveractivity然后按回来它开始主要活动罚款,但然后双击只返回gameoveractivity我不知道为什么当我从gameoveractivity开始main活动时我称之为完成。
mainscreenactivity:
// button listeners
playButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent gameActivityIntent = new Intent(MainScreenActivity.this, GameActivity.class);
startActivity(gameActivityIntent);
overridePendingTransition(R.anim.righttocenter, R.anim.centertoleft);
finish();
}
});
settingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent settingsActivityIntent = new Intent(MainScreenActivity.this, SettingsActivity.class);
MainScreenActivity.this.startActivity(settingsActivityIntent);
overridePendingTransition(R.anim.righttocenter, R.anim.centertoleft);
}
});
gameactivity:
// handle hardware back button
@Override
public void onBackPressed() {
Intent mainScreenActivityIntent = new Intent(GameActivity.this, MainScreenActivity.class);
startActivity(mainScreenActivityIntent);
overridePendingTransition(R.anim.lefttocenter, R.anim.centertoright);
finish();
}
处理游戏活动的逻辑代码:
if (weight.getBounds().intersect(player.getBounds())) {
timer.cancel();
gameTimer.cancel();
player.setTouched(false);
save(score, time);
Intent gameOverIntent = new Intent(this.getContext(), GameOverActivity.class);
this.getContext().startActivity(gameOverIntent);
((Activity) this.getContext()).finish();
}
gameoveractivity:
// handle hardware back button
@Override
public void onBackPressed() {
Intent mainScreenActivityIntent = new Intent(GameOverActivity.this, MainScreenActivity.class);
mainScreenActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
GameOverActivity.this.startActivity(mainScreenActivityIntent);
overridePendingTransition(R.anim.lefttocenter, R.anim.centertoright);
finish();
}
修改:通过添加以下内容来管理以解决此问题:gameOverIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
在创建gameoveractivityintent之后的游戏逻辑代码中。
答案 0 :(得分:1)
通过添加以下内容来管理解决此问题:
gameOverIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
在创建gameoveractivityintent后的游戏逻辑代码中。