Skip to content Skip to sidebar Skip to footer

How To Display A One Time Welcome Screen?

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 a

Solution 1:

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

In your activity:

SharedPreferences mPrefs;
finalStringwelcomeScreenShownPref="welcomeScreenShown";

/** Called when the activity is first created. */@OverridepublicvoidonCreate(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 foundBooleanwelcomeScreenShown= mPrefs.getBoolean(welcomeScreenShownPref, false);

    if (!welcomeScreenShown) {
        // here you can launch another activity if you like// the code below will display a popupStringwhatsNewTitle= getResources().getString(R.string.whatsNewTitle);
        StringwhatsNewText= getResources().getString(R.string.whatsNewText);
        newAlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(whatsNewTitle).setMessage(whatsNewText).setPositiveButton(
                R.string.ok, newDialogInterface.OnClickListener() {
                    publicvoidonClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
        SharedPreferences.Editoreditor= mPrefs.edit();
        editor.putBoolean(welcomeScreenShownPref, true);
        editor.commit(); // Very important to save the preference
    }

}

Solution 2:

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.

Solution 3:

I created a SplashScreen with this:

package com.olidroide;


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;


public class SplashScreen extends Activity{
/** Called when the activity is first created. */
     public ProgressDialog myDialog; 

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);

        new Handler().postDelayed(new Runnable() {

            public void run() { 
                myDialog = ProgressDialog.show(SplashScreen.this,"", "Loading", true);

                Intent intent=new Intent(SplashScreen.this,OtherActivity.class);
                SplashScreen.this.startActivity(intent);
                myDialog.dismiss();
                SplashScreen.this.finish();     
            }

        }, 3000);// 3 Seconds
    }
};

Post a Comment for "How To Display A One Time Welcome Screen?"