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 app is first installed; because after I will handle the update of the file myself.
Please how can it be done?
Thanks for any suggestion
You can do this, by using shared preferences . Store a value in shared preferences: SharedPreferences prefs = getPreferences(MODE_PRIVATE); SharedPreferences. Editor editor = prefs.
With Google Play Instant, people can use an app or game without installing it first. Increase engagement with your Android app or gain more installs by surfacing your instant app across the Play Store and Google Play Games app.
The general rule is that either onDestroy() is called, or your process is terminated, or your code crashed.
to do something only once in app you need something like this :
boolean mboolean = false;
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
mboolean = settings.getBoolean("FIRST_RUN", false);
if (!mboolean) {
// do the thing for the first time
settings = getSharedPreferences("PREFS_NAME", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("FIRST_RUN", true);
editor.commit();
} else {
// other time your app loads
}
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();
}
Create a launcher activity that loads when your app starts. Have it check for a value (such as firstStartUp) in SharedPreferences (http://developer.android.com/guide/topics/data/data-storage.html#pref) . The first time you ever run the app this value will not exist and you can update your data. After your data is updated set the value in shared preferences so that your app finds it the next time it launches and will not attempt to update the data again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With