Android onBackPressed/onUserLeaveHint

后端 未结 2 1599
感动是毒
感动是毒 2020-12-03 18:20

Just a bit of advice needed really. I have an Activity running with my game in it and when the user presses the Back button it will exit back to the Main Menu using the onBa

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 19:07

    Just an idea that might help you, i'm using it for my "home-made" ActionBar to determine when the user has actually arrived at the main (and last) activity before exiting. I start the Main-Activity manually and clear the whole activity stack by setting the FLAG_ACTIVITY_CLEAR_TOP flag, so if the user now hits the back button once again, the app is gonna get closed.

    Intent intent = new Intent(getContext(), MainMenu.class).
    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

提交回复
热议问题