How can i create a function that will be run only once, on first installation? I am trying to create an 开发者_如何学JAVAinformation that displays one time.
thanks in advance.
You could use a flag in the shared preferences.
Then on every startup you check this flag. If it is not set you display your first time message and then set the flag.
For example:
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean firstStart = settings.getBoolean("firstStart", true);
if(firstStart) {
//display your Message here
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("firstStart", false);
editor.commit();
}
}
精彩评论