15

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.

The Trav
  • 1,955
  • 3
  • 22
  • 30

5 Answers5

17

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;
    }
Primal Pappachan
  • 25,857
  • 22
  • 67
  • 84
  • 4
    Even better than comparing getString() to null is to use contains(). – Plutor Nov 07 '10 at 15:01
  • 7
    Even better using a boolean instead of a String. `editor.putBoolean(PREF_FIRST_LAUNCH, false);` and the first_time_check contains just `return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean(PREF_FIRST_LAUNCH, true);` – Sylphe Sep 21 '12 at 15:49
  • I used this method. But I'm having problems with be back button. When the app exits using back button, the next time it is started it assumes it's NOT its first run. Which is not one wants for an Android app cause the programmer not to be able to set everything to their initial value for app start. What am I supposed to do? – Fatima Jul 22 '14 at 06:43
  • where does the first_time_check() method go? In the first default activity or some other class? I have a WelcomeLogin activity that is only used the first time the app is opened, after that the app is automatically set to the next in sequence, DashActivity. So where does this code snippet go? – Darth Coder Mar 31 '15 at 00:09
4

i like dweebsonduty's method. a similar way to do this is to save their configuration information in files on the SD card. your app could start out by checking for those files and loading the information. if the load is successful, it moves on to the next activity, if not it starts the appropriate activity to prompt the user for input.

I have done this same thing, but instead of swiching activities i just switch views until i have all the info i need, and then move on.

mtmurdock
  • 12,756
  • 21
  • 65
  • 108
2

Many applications actually store the current version in SharedPreferences, and check against it for if an update has been installed. Its a clever way of achieving a "what's changed" popup, or making sure that some settings get set (I would be wary of just having a boolean flag because if you ever want to add an additional setting, you will need a second flag and it gets messy after the third, etc.).

Guzba
  • 2,671
  • 1
  • 18
  • 14
1

String VersionValue = "v.1.0"; final String PREFS_NAME = "MyPrefsFile";

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

    if (settings.getBoolean(VersionValue, true)) {
        //the app is being launched for first time, do something        
        NewDialogFragment newFragment = new NewDialogFragment();
        newFragment.show(getFragmentManager(), "New");
        // record the fact that the app has been started at least once
        settings.edit().putBoolean(VersionValue, false).commit(); 
    }

You could do it this way and still get the same result I tried it its a small workaround if u do not fully understand how to check if the app is updated. Instead with this code you can just simply change the String VersoinValue to your current app version and android will think the app is a new first time app and will only display the code u wrote once until you change VersionValue on your next update. (:

  • Even better! You could create a string in your string.XML file and reference that to both your version Number and your VersionValue in your main activity.java file. [ Be sure to also put the code above w/ the version value and stuff in the OnCreate meathod ] – Braxton Nunnally Sep 03 '14 at 12:34
0

How will you be storing the configuration?

If it is in SQLlite you could just create a table called firstuse and put a field in there called hasbeenused and make it null. Then when the app is used you can put a 1 in there. Then you can read it each time your app loads and if that field = 1 then go to your next activity.

shaneburgess
  • 15,702
  • 15
  • 47
  • 66
  • 2
    Maybe he doesn't even need the extra field; he could just check to see if the required configuration information is in there and if not, throw up the activity. That seems more extensible anyway. – tloflin Jun 09 '10 at 22:45
  • 1
    I did try setting it up with shared preferences, however that causes bad behavior of the back button. I looked for some way of manipulating the stack, but it seems to only want to do that for activities of the same type – The Trav Jun 10 '10 at 01:53