Possible Duplicate:
Is there on install event in android?
I want to execute a piece of code only once after installation complete in an Android app. This code should never be executed in the application there after.
Can anyone tell me how to do this.
Reagrds,
Shankar
I tried below code to make this work change it to suit your needs
SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
if (isFirstRun)
{
// Code to run once
SharedPreferences.Editor editor = wmbPreference.edit();
editor.putBoolean("FIRSTRUN", false);
//editor.commit();
editor.apply();
}
You can make use of an Shared Prefrence to maintain the number the times the app has been launched. So now if the app has been launched for the first time you can execute your code, if not you can just skip it.Here is a perfect demo for it.
http://marakana.com/forums/android/examples/63.html
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