Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splash-screen approach in single Activity app

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.

like image 702
Paul Avatar asked Oct 16 '18 12:10

Paul


People also ask

How do I create a splash screen activity?

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.

What is the splash screen of an app?

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.

How does a splash screen work?

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.


1 Answers

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.

like image 105
Eric Martori Avatar answered Sep 23 '22 22:09

Eric Martori