so I'm coding an app in Android Studio with Java right now for my company (I'm working in a daycare for school children) in which the kids are able to check themselves in. (Coming from school to us, click on their name and then its in a list)
At one activity there is a lock button at the top, so that if it is pressed the user is forbidden to exit the app or return to the previous activity without entering a password. So kids can't mess with it.
I've already searched some time in the existing threads but I've only found one solution that came close and since I'm not really a coder I don't know very much about it, just the basics.
What I've already tried:
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);
and
public void onBackPressed(){
Toast.makeText(getApplicationContext(),"You Are Not Allowed to Exit the App", Toast.LENGTH_SHORT).show();
}
I know I haven't changed the first one because I didn't know what to do and I can't find anything for it.
I've made an AlertDialog for the Button for safety. Some of my colleagues aren't too familiar with electronic devices and need everything foolproof.
This is what I've coded for the AlterDialog so far:
eGeoeffnet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder myAlertBuilder2 = new AlertDialog.Builder(Anmeldung.this);
myAlertBuilder2.setTitle("Navigation sperren");
myAlertBuilder2.setMessage("Möchtest du die Navigation sperren?");
myAlertBuilder2.setPositiveButton("Ja", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
myAlertBuilder2.setNegativeButton("Nein", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Anmeldung.this, "Du hast 'Nein' ausgewählt!", Toast.LENGTH_SHORT).show();
}
});
myAlertBuilder2.show();
}
});
Could someone tell me what I need to put into the positiveButton area?
Translation for the german parts:
"Navigation sperren" -> Lock navigation
"Möchtest du die Navigation sperren" -> Do you want to lock the navigations?
"Ja" -> Yes
"Nein" -> No
"Du hast 'Nein' ausgewählt!" -> You've chosen 'No'!
"Anmeldung" -> Log In
"Geoeffnet" -> Opened
I hope my thread doesn't sound too stupid, as I said earlier, I'm no real coder, it's just a hobby of mine.
Thanks in advance for your time!