13

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?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Nerd
  • 175
  • 1
  • 3
  • 8
  • I can't think of any scenario in which user should not in be control of his device or the app. Also in extreme cases user can just power off device (pull battery) and restart the device without again restarting the said app. – Master Chief Apr 07 '13 at 11:47
  • 2
    @MasterChief he wanna use the application inside the restaurant where he doesn't want his workers to play angry birds using a freaking new android phone while working !. got it ? – Kosh Apr 07 '13 at 12:26
  • 2
    @StyleMe You got it! ;) Not for workers but for clients.. Clients can see the restaurant's menu on tablet; the device isn't their smartphone/tablet, but it's mine – Nerd Apr 07 '13 at 12:33
  • @Nerd then check my answer below. – Kosh Apr 07 '13 at 15:36
  • @StyleMe Thank you! I'll try it.. but with this code how can I exit from app? – Nerd Apr 09 '13 at 06:08
  • you can use double clicks on the back button or any method u like , just call finish(); – Kosh Apr 09 '13 at 08:28
  • What you are looking for is a Kiosk mode app, I remember reading that on 4.2 it is possible to write home screen application that in behaviour will work like that: http://commonsware.com/blog/2013/02/20/android-4p2-for-kiosk-apps.html – marcinj Apr 07 '13 at 11:57

1 Answers1

2

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.

Kosh
  • 5,883
  • 2
  • 34
  • 67