Q:

Android:Splash screen only for the first time

I need to create a splash screen that should displays only at the first time when an application is installed and launched and from the second time the when the app is launched it should shows the main activity?How can i achieve it ?

A:

Okey looking at your problem you can do following..
First of all declare object of SharedPreference and on String which will we use later.
SharedPreferences loginPreference;
String MY_PREF = "my_pref";

Now in onCreate of your SplashActivity, do something like this.
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // initialize SharePreference
    loginPreference = getSharedPreferences(MY_PREF, Context.MODE_PRIVATE);

    // this condition will do the trick.
    if(loginPreference.getString("tag", "notok").equals("notok")){

        // add tag in SharedPreference here..
        Editor edit = loginPreference.edit();
        edit.putString("tag", "ok");
        edit.commit();

        // your logic of splash will go here.
        setContentView(R.layout.splash);

    }else if(loginPreference.getString("tag", null).equals("ok")){
        Intent i = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(i);
        finish();
    }
}

Happy Coding..

