1

I'm developing an mobile where the walkthrough page about the application should appear only once the application is installed. Can anyone help me resolving this issue with a clear example.

Parthiban M
  • 1,104
  • 1
  • 10
  • 30
  • 1
    Hold a `boolean indicator` initially as `false`in `SharedPreferences` then in application opening show walkthrough if that is `false` and change it to `true` to not run your walkthorugh `function` again – hrskrs May 15 '15 at 13:24

1 Answers1

1

Add the following code in your method:

SharedPreferences prefs = getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE);

// Default value returned by next line is true.
boolean firstLaunch = prefs.getBoolean("firstLaunch", true);
if (firstLaunch) {
  // Do whatever you want here. This will be called only the first time the app launches.

  // Then edit the SharedPreferences and put the value as false. Unless changed back to true, this if statement/loop will never be called again.
  prefs.edit().putBoolean("firstLaunch", false).apply();
}

Note: PREFERENCES_NAME is just a String. It can be anything. I suggest you use the same PREFERENCES_NAME in all of your app, in case you need to access SharedPreferences somewhere else.

Karim
  • 5,298
  • 3
  • 29
  • 35