0

I am developing a parental control app. I need to restrict bottom navigation button usages , some how I restricted Menu and Back button usages butI couldn't restrict home button usage , I came to know that home buttons cannot be restricted (Correct me If I am wrong..!) so I need to redirect to the previous activity when Home button is pressed. I tried Lots of methods (Some of them are below)

1.Can I override the 'Home' button in my application?

2.How can I disable the hardware menu button in my app?

3.https://abhik1987.wordpress.com/tag/android-disable-menu-button/

These are recommended by most of the people yet it doesn't work for me.

If any one got better alternate solution kindly notify me.

Thanks in Advance.

Swati Garg
  • 995
  • 1
  • 10
  • 21
Suresh S
  • 41
  • 10
  • You can receive a broadcast after clicking home button,and then you can direct your activity to main activity,but you can't stop android enter launcher. – aolphn Oct 19 '18 at 11:06

1 Answers1

0

Why not do something like so. In the activity that was open before home pressed override the onResume() method. In it

Intent blockUserFromComingBack = new Intent(ActivityUserWasOnVeforePressingHome.this, HomeActivity.class);
ActivityUserWasOnVeforePressingHome.this.startActivity(blockUserFromComingBack);

This would allow activity to run an onStart but if it ever Pauses "such as the user presses home" when it resumes it will navigate user to the home activity.

Vahalaru
  • 380
  • 4
  • 15