Can I have an android activity run only on the first time an application is opened?

The Trav picture The Trav · Jun 10, 2010 · Viewed 20.3k times · Source

OK, so I'm playing around with an android app.

The 90% use case is that users want to go straight to the primary list screen to find what they're looking for. That's what I want as my default screen.

The first time a user loads the app however, some configuration is required before their list screen is of any value to them.

So my question, is how I can go about displaying the configuration activity the first time the app is opened up, and then the list screen for future openings.

I also want to put a demo button on the configuration screen, so I suppose more than just detecting that it's the first time, I specifically want to detect whether the user has performed certain configurations within the first screen.

Answer

Primal Pappachan picture Primal Pappachan · Jun 10, 2010

After the first time the user has loaded the app you could store the details of whether user has performed the configurations in SharedPreferences.

 protected void storeSharedPrefs(String value) {
        /*
         * Storing in Shared Preferences
         */
        editor.putString("first", value);
        editor.commit();  //Commiting changes
    } 

Check each on time application is loaded, whether its the first time and configuration details has been entered correctly by checking SharedPreferences

private boolean first_time_check() {
        /* 
         * Checking Shared Preferences if the user had pressed 
         * the remember me button last time he logged in
         * */
        String first = uPreferences.getString("first", null);
        if((first == null)){
            return false;
        }
        else 
            return true;
    }