How can I execute something just once per application start?

前端 未结 10 1449
感情败类
感情败类 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条回答
  •  旧时难觅i
    2020-11-28 07:20

          try {
    
              boolean firstboot = getSharedPreferences("BOOT_PREF",MODE_PRIVATE)
        .getBoolean("firstboot", true);
    
                        if(firstboot){
                    //place your code that will run single time                  
    getSharedPreferences("BOOT_PREF",MODE_PRIVATE).edit().
        putBoolean("firstboot", false)
                            .commit();
    
    
                        }
    

提交回复
热议问题