Exiting Application on Android

Warning! Massive technical rant ahead!

Android RantAnyway, a couple hours ago, I just realized that I haven’t implemented an “exit app” functionality on my game. So of course, I fired up Google and searched for how to exit an android application.


Most of the results said that I should use finish() function that behaves just like using back button (which isn’t available for me since I override the key press). Oh, and usually these stuff are accompanied with some lengthy reasons about why you shouldn’t have an exit functionality on android application XD

Apparently, the function doesn’t really worked well for me. Sure, I got back to the homescreen when I executed it, but the application doesn’t actually got destroyed =/ It usually wouldn’t be a problem, since the activity would still call the onCreate() method where we put most of our initialization stuff. Things are different with singleton classes though, since they AREN’T destroyed, they didn’t get instantiated again when the activity is started. So we are left with the old instance of the class, containing all the old values. I could have added an initialize() method on those classes that will be executed on the onCreate() method, but this would defeat the purpose of singleton classes, where you don’t need to instantiate the class.

So, even with all those articles that say people should be using finish() function, I still found the functions doesn’t work the way I had hoped. What I really want is to destroy the application utterly when the user quits, unfortunately, finish() just doesn’t cut it, and in the end I resort to the killProcess() function to destroy my own application.


There’s also that System.exit() function, though I don’t really know the difference XD


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s