내 주요 활동에서 하드웨어 뒤로 버튼을 눌러 앱을 종료하라는 알림을받습니다. 이것은 사용자가 죽을 때를 제외하고는 대부분의 환경에서 작동합니다. 사용자가 죽으면 GameOverActivity로 이동합니다. 사용자가이 액티비티에서 뒤로 버튼을 누른 다음 주요 액티비티를 두 번 뒤로 누르면 액티비티가 다시 시작됩니다. 여기 코드가 있습니다, 나는 게임에서 뒤로 버튼에 finish()를 선언했지만, 도움이되지는 않습니다.눌려진 하드웨어 버튼을 두 번 닫으면 이전 활동으로 돌아갑니다.
MainScreen 다시 종료하는 방법
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press again to quit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
GameOverActivity 코드 :
if (weight.getBounds().intersect(player.getBounds())) {
player.setTouched(false);
Intent gameOverIntent = new Intent(this.getContext(), GameOverActivity.class);
this.getContext().startActivity(gameOverIntent);
((Activity) getContext()).finish();
}
대신 즉시 시작 활동 후
MainScreen
에서finish()
를 호출해야합니다; 시도해보십시오 – jyomin아무런 변화가 없었습니다 –