I am looking for some way to disable the functions of the navigation bar buttons so that my app can not be closed.
Thank you very much.
I am looking for some way to disable the functions of the navigation bar buttons so that my app can not be closed.
Thank you very much.
Disable the functions of the three buttons (Back, Home, change of android app.
In the specific case of Home and when changing applications, your application changes to the background and this can be closed when the operating system requires memory, this definitely can not be avoided . What you can do is save the necessary values to rebuild the last state of your application in case it was closed.
As for the "back" button, the onBackPressed () and we simply indicate that it does not have any functionality:
@Override
public void onBackPressed() {
// do nothing.
}
onBackPressed () Called when the activity has detected the press of the user of the backspace key ("back"). The implementation default simply ends the current activity, but you can Cancel it to do what you want.
Try this, at least for this example it prevents the back button from working, just add the button and the home button or the buttons you want to modify it to your liking.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
Along with recommending that in most cases it is not a good idea to force a device in "kiosk" mode, I can offer some partial solutions.
Go back is the simplest task. You only have to make an override in your Activity
of:
@Override
public void onBackPressed() {
// no vamos a hacer nada aquí
}
Since Android IceCreamSandwich (4) is no longer as simple to manipulate the function of the Home
button, but you could re-launch your activity every time it goes to the bottom.
What should work is to re-launch your app with a new Intent
with the FLAG_ACTIVITY_SINGLE_TOP flag from onStop()
. That should guarantee you in all cases that your app persists in the foreground. Keep in mind that in this case you will not call onCreate(Bundle b)
but onNewIntent(Intent i)
.
It is very important that you make sure that there is a way in your app to exit that works on all devices, or at least that your app does not automatically re-launch after a reboot. Google changed the policy of modifying these buttons for just that.
Good morning, what you need is to make your App the same launcher. That way you will not be able to access the "home" to enter other Apps, and as you are the launcher you do not give access to other applications. The back is solved with the onbackpressed.
Look up information about the "Koisk Mode".
I leave a link that will help you a lot: link
Greetings.