Home button listener

后端 未结 4 747
面向向阳花
面向向阳花 2020-11-30 13:24

Using the setOnKeyListener I can able to listen for all physical buttons except Home and End button, is there any possibility to catch the action of Home button.

4条回答
  •  日久生厌
    2020-11-30 13:59

    You do not need to catch Home button. If user press Home and some other Activity comes to foreground, your app goes to background and onPause() is called in your current Activity. You may override that function to clean search string or anything you need.

    UPDATE:

    More clean solution is to use flag FLAG_ACTIVITY_NO_HISTORY when starting that critical activity. So, when your activity goes to background system will close it properly for you.

提交回复
热议问题