0

I am working on a use case where if the user presses on the home button, a different activity should be shown in the recents list. I don't want to see the activity which user is seeing when he/she presses the home button or recents button.

I am trying to intercept the onPause( ) method for this. If we try to start a different activity in the onPause() method, it would show that activity on the screen and would violate the home button use case.

Can someone please let me know if it is possible to do this?

Thanks in advance.

pg238
  • 1,145
  • 2
  • 15
  • 26
  • You cannot intercept the Home button from a normal App, but you can register a [launcher activity](http://stackoverflow.com/questions/9704898/how-to-set-my-activity-as-main-activity-in-android) which Android will call when the Home key is pressed. – adelphus Oct 29 '15 at 17:46
  • Thanks, adelphus. when you press home button, the activity's onPause( ) method gets called. That is where I am trying to see if I can show the passcode activity instead of the activity on which user presses the home button. – pg238 Oct 29 '15 at 18:06
  • No, you can't do this from `onPause`. Android defines a minimum 5 second period which stops Apps from launching other Activities when they are paused. It's to discourage developers from creating apps which the user cannot escape from (which is what I think you're trying to do). – adelphus Oct 29 '15 at 18:32
  • I am trying to show a screenshot of some sort (may be change the current layout on the main activity) instead of the main activity, because of the security reasons. I can do this from onPause( ) too, right? – pg238 Oct 29 '15 at 18:40
  • Ok, I see what you're getting at. You just want the user to see a different screen for your app in the recents list, rather than the actual screen of the app. I don't think changing or hiding the layout during `onPause` will help, but you know you can [exclude your Activity from the recents list](http://stackoverflow.com/questions/3762763/how-to-remove-application-from-recent-application-list) - is that good enough? – adelphus Oct 29 '15 at 18:52
  • Yup. I know about excluding the activity from recents list. Unfortunately, the requirement is to show the activity in the recents list :( – pg238 Oct 30 '15 at 16:34

0 Answers0