0

I'm trying to build a screen-lock app. However, I'm experiencing a gaping hole in the system. The moment the user clicks/touches/presses the home button, the activity goes to the background. How do I prevent that? Is that possible?

I'd like a detailed explanation on how to do it.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Sunny
  • 1
  • 2
  • 1
    You cannot prevent the home button taking the user to the launcher. It is a fundamental security feature of Android. There is nothing you can do to stop it, and that's a very good thing. You are welcome to build your own version of Android to provide the ability for apps to override this. – Simon Nov 03 '13 at 07:36

1 Answers1

0

No it is not possible to prevent activity goes to the background but you can catch event when you pressed home button so you can release resources or do any other stuff when activity goes to background.

you can override onStop method

@Override
        protected void onStop() {

            super.onStop();
        }
Hardik
  • 17,179
  • 2
  • 35
  • 40
  • Thanks for the response, could you be a little more detailed as to how and what you're trying to say? – Sunny Nov 03 '13 at 07:08
  • i am just to trying to explain you that you can only catch event of home button but not prevent activity to goes in background. you can catch event of home button in onstop() method. – Hardik Nov 03 '13 at 07:12
  • What about the abortBroadcast() method? What exactly would that do if I used it on this? – Sunny Nov 03 '13 at 07:32
  • Or how about this: The moment the home button is pressed, I recall the activity if it has gone to the background, and bring it back to the foreground. Would that be a reasonable hack to work my way around it? – Sunny Nov 03 '13 at 07:39
  • no it is not right way to do that but if you do not found any other way you can do that way. put your start activity code after super.onStop(). – Hardik Nov 03 '13 at 07:42
  • What are you trying to do? Why not create your own lockscreen? You are trying to hack Android in a way which will not be a good experience for the user. – Simon Nov 03 '13 at 09:05
  • Simon, I'm creating an activity of my own, and I'm using a really advanced storage mechanism for the password. My objective is to get this activity I created to be called every time the user unlocks his phone, so that it may offer better security. And also, I don't want to have the screen go to the background every time he/she presses the home button since it would be a sham if a lock could be surpassed by just clicking home, and there wouldn't any point of a password entry. – Sunny Nov 03 '13 at 11:04