Android onBackPressed/onUserLeaveHint

后端 未结 2 1584
感动是毒
感动是毒 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 18:53

    onUserLeaveHint() is a protected method as other lifecycle methods of the activity and if you are handling onUserLeaveHint this will take care of the following case

    1. When User hits home key
    2. When User hits back key
    3. When User hits annunciator bar

    Basically it hints about the user is trying to leave your activity. That means if you are handling onUserLeaveHint() you don’t need to handle onBackPressed() in your code.

提交回复
热议问题