2

I am creating a home screen lock application. i want to disable the home button so that the user cant go further without unlocking the screen.

As we know as long as we are not the home screen we cant really disable the home button. so i started my activity again in my onPause() method. so that when user press home button the application goes to background and onPause() is fired and i start the activity again.

@Override
protected void onPause() {
    super.onPause();
    startActivity(new Intent(getApplicationContext(), LockScreen.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION));
    finish();
}

but the problem once the home button is pressed the app goes to background and it takes like 2 seconds to again start the activity and come to foreground.

Is there any faster solution for this ? how can i start the activity as soon as the home button is pressed ?

Update

Do not tell e we have to be the home screen to able to disable the home button . if this is the case then there must be a walk around because screen lock apps do it.

My question has been marked as duplicate . but please read the answer given . it does not answer my question. i want to override the home button without being the home screen . and if you say its not possible then please see any screen lock app in play store. so please suggest any other solution. you ca search the whole SO and please delete this question if you can still find a working answer to this question. and if not please dont suppress the question.

Sagar Nayak
  • 2,138
  • 2
  • 19
  • 52
  • who has down voted the question. can you please tell what is wrong with the question if you have the knowledge what i am talking about . – Sagar Nayak May 21 '16 at 13:24

1 Answers1

1

The Home button is a very dangerous button to override and, because of that, Android will not let you override its behavior the same way you do the BACK button.

Take a look at this discussion: Overriding the Home button - how do I get rid of the choice?

You will notice that the home button seems to be implemented as a intent invocation, so you'll end up having to add an intent category to your activity. Then, any time the user hits home, your app will show up as an option. You should consider what it is you are looking to accomplish with the home button. If its not to replace the default home screen of the device, I would be wary of overloading the HOME button, but it is possible (per discussion in above thread.)

Community
  • 1
  • 1
Tilak Madichetti
  • 4,110
  • 5
  • 34
  • 52
  • 2
    so how do the screen lock apps disable the home button ? when the screen is locked by any screen locker app then you cant do anything by pressing the home button right ? so how do they do that ? – Sagar Nayak May 21 '16 at 12:50