tags:

views:

127

answers:

3

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.

+7  A: 

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.

benvd
So Preferences as in the Android Preferences? That just might be what I am looking for. Will give it a shot.
Siddharth Lele
Yep, that's what I meant. I've no idea if is this "how it's done" on Android, but it's how I do it. :)
benvd
Preferences? I should notice it for me. We're doing it now by storing some settings in files.
Mur Votema
I use the same solution, works well.
Scythe
I think you have set me in the right direction with that. Will post comments when done. Thanks a bunch. :)
Siddharth Lele
That's it. That worked like a charm. Thanks to all who contributed. :)
Siddharth Lele
A: 

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
    }

}
Martyn
This might work better than what I could conjure. Just one quick question. What is the version number for?
Siddharth Lele
@Siddharth: I'm guessing so the message still shows up (once) after updating the application.
benvd
Makes sense. What's your opinion about the code posted?
Siddharth Lele
ah..ok, sorry - I didn't clean this code out properly. This code will check the version number stored and popup the message is the current version number of the app is different. for context, I used this to popup a message when the user upgrades the app - I can post the correct code for you if you like?
Martyn
My opinion? If you want to display the message after each upgrade, use this. If not, use what I suggested. (Which is basically the same as this, minus a few lines.)
benvd
@benvd: Your suggestion works like a charm. I have got it working just the way I had wanted it to. That said, a combination of both will serve different purposes.
Siddharth Lele
@Martyn: I would love to see the correct code. For an amateur like myself, even a part of some refined code coming from experienced folks like you is just brilliant. :)
Siddharth Lele
A: 

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
    }
};
olidroide
It really isn't a splash screen. I need to display some tips and hints when a user installs and runs the application for the first time. More like a tutorial and a walk-through. Thanks for the help though..... :)
Siddharth Lele