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
-
It just a layerlist with logo in center background color with it.
Now open styles.xml and add this 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.
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.