Created
May 29, 2013 11:17
-
-
Save zerho/5669570 to your computer and use it in GitHub Desktop.
Android First app launch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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