Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a one time welcome screen?

Tags:

In my android app, I need to design a Welcome Screen which will be shown to the user only once after the app is installed and opened. The app in question is a database driven app and I would love to include some 3 - 4 screens to help the user create re-usable resources for use within the app and a few tips. They would be Dialog Alerts with the last welcome screen showing the "Do Not Show Again" checkbox.

The problem really is, how to show the welcome screen just once. Any help or pointers to that effect are much appreciated.

like image 953
Siddharth Lele Avatar asked Oct 20 '10 09:10

Siddharth Lele


People also ask

How do I show onboarding screen once in react native?

You should clear the app data on your Android emulator and remove the app from your iOS simulator, then rebuild the app using the npx react-native run-ios and npx react-native run-android. You should see the onboarding screens once; after that, it shouldn't show up anymore.

How do I make Android activity only appear once?

Now in the onResume() method, check if we already have the value of prevStarted in the SharedPreferences. Since it will evaluate to false when the app is launched for the first time, start the MainActivity (Which we want to appear just once) and set the value of prevStarted in the SharedPreferences.


2 Answers

Here's some code from my application which does just that.

In your activity:

SharedPreferences mPrefs; final String welcomeScreenShownPref = "welcomeScreenShown";  /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);      mPrefs = PreferenceManager.getDefaultSharedPreferences(this);      // second argument is the default to use if the preference can't be found     Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);      if (!welcomeScreenShown) {         // here you can launch another activity if you like         // the code below will display a popup          String whatsNewTitle = getResources().getString(R.string.whatsNewTitle);         String whatsNewText = getResources().getString(R.string.whatsNewText);         new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(whatsNewTitle).setMessage(whatsNewText).setPositiveButton(                 R.string.ok, new DialogInterface.OnClickListener() {                     public void onClick(DialogInterface dialog, int which) {                         dialog.dismiss();                     }                 }).show();         SharedPreferences.Editor editor = mPrefs.edit();         editor.putBoolean(welcomeScreenShownPref, true);         editor.commit(); // Very important to save the preference     }  } 
like image 63
Martyn Avatar answered Sep 20 '22 21:09

Martyn


Save a flag in the Preferences when you start up the application, after you've done the welcome screen stuff. Check for this flag before you show the welcome screen. If the flag is present (in other words, if it's not the first time), don't show it.

like image 25
benvd Avatar answered Sep 23 '22 21:09

benvd