I am trying to decide on the best approach for creating an app splash-screen while taking into consideration Google's latest recommendations on choosing a single Activity app whenever possible.
See here:
"The new approach is to use one-activity structure whenever possible."
and here:
"Today we are introducing the Navigation component as a framework for structuring your in-app UI, with a focus on making a single-Activity app the preferred architecture."
Any good splash-screen approaches I have found have a dedicated Activity for the splash screen:
See here
and here
Has anyone else had any experience creating a splash screen in a single Activity app? Does the the single Activity recommendation include the splash-screen or is it a special case? Does anyone have any good examples or advice on this?
Cheers, Paul.
The most straightforward way to create a simple splash screen was to create a dedicated theme overriding android:windowBackground with a drawable containing branding colors or a bitmap of a logo. The theme was set as an attribute of the launcher activity in AndroidManifest. xml.
Android Splash Screen is the first screen visible to the user when the application's launched. Splash screen is one of the most vital screens in the application since it's the user's first experience with the application.
Splash screen is the first graphical notification you receive when you visit any app. It can even appear as an introductory screen of an application. It also signifies that you have to wait for a few seconds before landing on the actual screen of the application.
The approach I use is the following:
First define a drawable for the background:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/green"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
2. Define a new style to use in the splashScreen:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
3. Make your activity implement use the splash theme:
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4. In on create, before the super invocation and before the set content view set the default app theme:
override fun onCreate(savedInstanceState: Bundle) {
setTheme(android.R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
}
This approach is the one I've been using even with multiple Activities, since it follows the guidelines laid down by google: itshows the splash right away and doesn't stay longer than needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With