Android: how to call method only on installation of App

前端 未结 4 2076
粉色の甜心
粉色の甜心 2021-01-05 23:21

I need to call a method (or start an activity, or something else) that will update a file containing data the app needs.

But I want it to be done only once, when the

4条回答
  •  抹茶落季
    2021-01-05 23:45

    You can do it by using SharedPrefrences . Look this:

    SharedPreferences ratePrefs = getSharedPreferences("First Update", 0);
            if (!ratePrefs.getBoolean("FrstTime", false)) {
    
            // Do update you want here
    
            Editor edit = ratePrefs.edit();
            edit.putBoolean("FrstTime", true);
            edit.commit();
            }
    

提交回复
热议问题