Abdullah's answer is great. But i want to add some more details to it with my answer.
Implementing a Splash Screen
Implementing a splash screen the right way is a little different than you might imagine. The splash view that you see has to be ready immediately, even before you can inflate a layout file in your splash activity.
So you will not use a layout file. Instead, specify your splash screen’s background as the activity’s theme background. To do this, first create an XML drawable in res/drawable.
background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
It just a layerlist with logo in center background color with it.
Now open styles.xml and add this style
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
This theme will have to actionbar and with background that we just created above.
And in manifest you need to set SplashTheme to activity that you want to use as splash.
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Then inside your activity code navigate user to the specific screen after splash using intent.
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
That's the right way to do. I used these references for answer.
- https://material.google.com/patterns/launch-screens.html
- https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Thanks to these guys for pushing me into right direction. I want to help others because accepted answer isn't a recommended to do splash screen.