First, create a drawable with the following content, the name of it being background_splash:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/gray"/> <!--aqui pode ser qualquer coisa, até uma imagem-->
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
Once you have done this, you will in your styles.xml place this code snippet:
<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
Then, in your manifest, you will put the following in the declaration of your activity, remembering that it has to be the launcher and main of the project:
<activity
android:name=".SplashActivity"
android:theme="@style/Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Ah in the activity onCreate, you can do all the processing needed. It does not even need to have the setContentView () statement:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Aqui você faz todo e qualquer processamento necessário, depois inicializa sua MainActivity e finaliza a splash, pra tirar ela do back stack.
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}