Reputation: 185
I've an android application that will be used in a restaurant, so I want that users can't exit from the app. The only thing that users can, is using application.
(If possible only admin can exit from app, by logging in or restarting device, I don't know which is the best way).
Is there a solution or other way to do this?
Upvotes: 14
Views: 32555
Reputation: 69
Android only provide back button override function. It will not allow user to disable home key and recently open key.
But we can replace the home screen to our application in this way first we select our application as a launcher. So, if user press home key the home screen replace to our application and it will only open our application. For this effect add these lines in Manifest file:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Upvotes: 3
Reputation: 6334
you can override
the onBackPressed
method
@Override
public void onBackPressed(){
Toast.MakeText(getApplicationContext(),"You Are Not Allowed to Exit the App", Toast.LENGTH_SHORT).show();
}
this will prevent the back button from exiting the application.
and then you will need to override
the home button
as well like
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.i("TEST", "Home Button"); // here you'll have to do something to prevent the button to go to the home screen
return true;
}
return super.onKeyDown(keyCode, event);
}
EDIT: for new devices with android version 4.0.xx you'll have to override
the recent apps button
as well
hope that helps you.
Upvotes: 2