I am currently developing an android app. I need to do something when the app is launched for the first time, i.e. the code only runs on the first time the program is launch
I made a simple class to check if your code is running for the first time/ n-times!
Example
Create a unique preferences
FirstTimePreference prefFirstTime = new FirstTimePreference(getApplicationContext());
Use runTheFirstTime, choose a key to check your event
if (prefFirstTime.runTheFirstTime("myKey")) {
Toast.makeText(this, "Test myKey & coutdown: " + prefFirstTime.getCountDown("myKey"),
Toast.LENGTH_LONG).show();
}
Use runTheFirstNTimes, choose a key and how many times execute
if(prefFirstTime.runTheFirstNTimes("anotherKey" , 5)) {
Toast.makeText(this, "ciccia Test coutdown: "+ prefFirstTime.getCountDown("anotherKey"),
Toast.LENGTH_LONG).show();
}
FirstTimePreference.java