AADTechnical AADTechnical - 6 days ago 4
Android Question

Android Splash screen duration

We are using the splash screen to show the company logo every time user open the app. Currently, we are showing the splash screen for 3 Seconds.

Below is the code:

private static int SPLASH_TIME_OUT = 3000; // Delay of 3 Seconds

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);


new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
Intent i = new Intent(SplashScreenActivity.this, AnotheActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}


But this splash screen duration is just randomly chosen within team.
We kind-of know that Splash screen in general is not all that encouraged in Android app ecosystem, but since this is our app's need, hence it is implemented.

My Question: Is there any standard Android guideline/best practice for choosing the RIGHT splash screen duration time?

Answer

A better option is to use a splash screen activity with a custom theme, that starts the main content activity. With this there is no need to use a timer, as it switches to main content when the app is ready, and in the meantime shows a picture that is inside the theme.

Here is tutorial how to do it - https://www.bignerdranch.com/blog/splash-screens-the-right-way/

Main parts from the tutorial:

<activity
    android:name=".SplashActivity"
    android:theme="@style/SplashTheme"> THEME HERE!!!
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

<style name="SplashTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>

</style>


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/black"/>

    <item>

        <bitmap

            android:gravity="center"
            android:src="@drawable/logo_image"/>

    </item>

</layer-list>

It is even possible to add the style to the application, without a need to use a separate activity.

Comments