You should not create a new thread at startup, instead you should create a view that should not wait for your resources to load, as described in this article: The screensaver paints the correct path .
As stated in the article, you should create a layer-list drawable instead of the XML layout file:
<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>
Then create a theme using the drawn file as the background. I use the background attribute instead of the windowBackground attribute, as suggested in the article, because background takes into account the status and navigation panels, improving the selection. I also set windowAnimationStyle to null so that the splash screen does not animate the transition to MainActivity :
<resources> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> </style> <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:background">@drawable/background_splash</item> <item name="android:windowAnimationStyle">@null</item> </style> </resources>
Then declare your theme in the manifest for your SplashActivity :
<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>
And finally, all you need to do in SplashActivity will launch your MainActivity , and the splash screen will only show until you need to configure the application:
public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } }
Bryan source share