Skip to content

Instantly share code, notes, and snippets.

@zerho
Created May 29, 2013 11:17
Show Gist options
  • Save zerho/5669570 to your computer and use it in GitHub Desktop.
Save zerho/5669570 to your computer and use it in GitHub Desktop.
Android First app launch
// Add this method to the Activity
private boolean isFirstLaunch() {
// Restore preferences
SharedPreferences prefs = getSharedPreferences("MainApp_PREFS", 0);
boolean isFirstLaunch = prefs.getBoolean("isFirstLaunch", true); // la chiave da cercare, se non esiste torna true
return isFirstLaunch;
}
// and copy this in the onCreate() implementation
if (isFirstLaunch()) {
startService(new Intent("it.udanet.server.service.HTTPService.ACTION_START"));
// set the bool to false in next activity !
prefs = getSharedPreferences("MainApp_PREFS", 0);
Editor editor = prefs.edit();
editor.putBoolean("isFirstLaunch", false);
editor.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment