How to show splash screen when USER install my application. I don't want to show splash screen every time when user opens it but Only when USER install it on the phone and opens it for the first time. How to achieve this?
Asked
Active
Viewed 1,247 times
2
-
3possible duplicate of [How do I make a splash screen?](http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen?rq=1) or [How to show splash screen only when the app starts “fresh”?](http://stackoverflow.com/questions/7682439/how-to-show-splash-screen-only-when-the-app-starts-fresh?rq=1) – V-rund Puro-hit Jul 30 '16 at 11:18
-
1You can use shared preference for the same. – Pravin Divraniya Jul 30 '16 at 11:18
3 Answers
2
In your Main Activity that you will be showing every-time on launching the app, Try the following logic.
SharedPreferences mPrefs;
final String splashScreenPref= "SplashScreenShown";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean splashScreenShown= mPrefs.getBoolean(splashScreenPref, false);
if (!splashScreenShown) {
Intent intent=new Intent(MainActivity.this,SplashScreenActivity.class);
startActivity(intent);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(splashScreenShown, true);
editor.commit();
finish();
}
}
Refer these links for better understanding on how to use SharedPreferences : link1, link2, link3
1
You need check every time when app will open that is it first startup of app ? if yes then show your one time splash screen else show main activity
you can use shared preference to store data about first startup.

Harish Kamboj
- 887
- 12
- 32
1
Here,
You should create application class and need to call your require activity from application class onCreate method.
public class Appli extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
//manage base on your requirement,you can use share preference for splash screen track
Intent intent = new Intent(this,Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".Appli"
android:theme="@style/AppTheme">
</application>
Above code sure work,i have tested.

ViramP
- 1,659
- 11
- 11