1

I want to check whether an activity just launched or not - so that I can perform (first time startup only actions e.g. attempt to load something and if it fails the first time let the user manually do it)

Currently I am doing this by checking if savedInstanceState == null on an Activity.onCreate method.

I am wondering how reliable this is? Is there a better alternative? Will savedInstanceState == null in any other scenario other than on Activity startup?

1 Answers1

0

you can use SharedPreferences at onCreate() method of otheractivity

 SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
    boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
    if (isFirstRun) {
    //do something
    }

By using this even if user delete app data by mistake this code will re-run.
You must be ready if the data is removed by user this could be achieved by SharedPreferences

phpdroid
  • 1,642
  • 1
  • 18
  • 36