I am developing a game on Android, and it requires an Internet connection to be played. I know how to check whether a connection is available or not, but I am not sure what to do in case the connection is not available.
My idea is to display a “No Connection Available” dialog to the user, with an “Exit’ button right below it, so that he can close the app from the dialog and fix his connection. I would be doing this with the System.exit(0) command.
However I’ve read in many places that I shouldn’t use that command or close my app, and instead let the OS handle this.
But how can I solve this situation without using System.exit(0)?
I believe the DrawSomething game also checks for an Internet connection and presents you with an “Exit” button in case you don’t have one. Not sure what method they are using to close the app though.
Check for the Internet connection in your first activity, and call
finish()to get rid of that activity if there is no Internet connection (or, more accurately, after the user clicks on your confirmation dialog).