Search code examples
androidandroid-activityandroid-activityrecord

Run Activity only for First time after installation of app Android


I am implementing an app which have MainActivity , onlyFirstRunActivity and alwaysRunActivity . Now i want that on app installtion or on updation of app my app cycle should be like that:

MainActivity -> onlyFirstRunActivity -> alwaysRunActivity

and after installing or on updation my app cycle should be :

MainActivity -> alwaysRunActivity

How can i implement this situation


Solution

  • You can get the update time for your app and save it in a SharedPreference.

    Also, you should just make your main activity the always run one.

    //In your onCreate for your main activity/.
    if(last_update_preference < current_update_time){
       Update last update preference to current update time.
       Run first activity. (Which will finish and bounce you back);
    }
    

    To get the current_update_time:

    How to get app install time from android

    For last update time, see:

    http://developer.android.com/guide/topics/data/data-storage.html#pref