First of all I would like to tell you that this is not the right way to add splash screen. There is no need of a handler at all.
In general splash screens are just that natural delay that you see when app launches. Adding your own delay of 5 seconds is Not Recommended At All.
Now if you want to stylize that natural delay and make a proper custom splash screen then you need to follow this procedure.
Start by creating a background_splash.xml drawable that will serve as the ui of splash screen
<?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>
Next you have to set this as your Spash screen background in style.xml
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </style> <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/background_splash</item> </style> </resources>
Now you configure your android manifest accordingly
<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> </activity>
Finally code your Splash screen java class like this
public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } }
Source: bignerdranch
So, you are how you didn't have to manipulate the application launch time with handler thread. This will eradicate the white background on app launch delay and give you customised xml drawable.
For reference you can check how all Google apps like YouTube etc launch without a white background delay and other high quality apps launch.
Please consider using this correct flow for your Splash screen. It's just a window background nothing complicated like multithreading, handler etc