How to Properly Quit App when Home Button is Pressed (can't detect or override Home button)
in
Android Processing
•
3 years ago
Using the Home button to exit my app does not work. After pressing home and restarting, the app has a blacked-out screen until I force close it (I believe the app is "running" because I see some printed debug text in the processing output space). Properly detecting the Home button and performing the appropriate quit sequence would be preferred but currently I'm trying to override the Home button. Quiting and restarting works perfectly when using the Back button.
void keyPressed() {
// doing other things here, and then:
if (key == CODED && keyCode == KeyEvent.KEYCODE_HOME)
{ // override the home key here }
}
I added the following to my code:
- public void onHomePressed() {
- // Do nothing...
- }
Thanks,
Gary
EDIT 1: I'm not certain I can use this to my advantage, but I found that the Home button calls onUserLeaveHint() however the Back button does not. onResume and onPostResume run when I restart whether I exited via Back or Home
EDIT 2: I recently noticed that print() statements in the setup() routine are not working when I restart the app after exiting via the Home button but they do execute when I exit via the Back button. print() statements in the draw() routine work either way.
1