How can I execute something just once per application start?

前端 未结 10 1446
感情败类
感情败类 2020-11-28 06:45

I\'d like to implement an update checker in an application, and I obviously only need this to show up once when you start the application. If I do the call in the onCr

10条回答
  •  误落风尘
    2020-11-28 07:18

     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      if (!prefs.getBoolean("onlyonce", false)) {
        // <---- run your one time code here
    
    
        // mark once runned.
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("onlyonce", true);
        editor.commit();
      }
    }
    

提交回复
热议问题