Proper exiting of openFrameworks Android app?

How can I do a proper exit from an OF Android app, such that whe I exit manually, the app is also removed from recent screen?

Currently, I use:

ofExit(); // doesn't exit fully on android?
std::exit(0); // does exit fully on android!

… and as it says, ofExit() doesn’t exit fully (it apparently just calls ofApp::exit() which could also be empty?), while std::exit(0) does - however, even in this case, the application will remain in Recent screens, and will start up anew if called from there.

Also with std::exit(0), sometimes (but not always), I will get the message “Unfortunately, YOUR_APP has stopped.” issued by Android, which is the message Android shows when an application crashes, so users don’t like it.

Also, I am aware I could use

void ofApp::exit()

… but I’m not exactly sure what I should include here - except, I know I shouldn’t use ofExit() here, as it causes recursion (since it apparently calls ofApp::exit()).

So, what would be the right way to close an Android app - including removal from Recent apps screen - upon a handler (say, from a click on a button)?

1 Like

I think you should call finish() from your main Activity.

(probably a JNI call away)

I’m converting my OF apps to Android, and wondering the same thing. In fact, my first observed bug after conversion is the apps can’t shut down with the methods that work for a computer version.

Does anyone happen to know a recommendation for how to shut down an Android app?

(I know that many Android apps don’t exit by default, but some do, without raising an alert about the app “unfortunately” stopping.)