Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 299
AADProgramming Avatar asked May 13 '16 11:05

AADProgramming


Video Answer


2 Answers

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.

like image 197
Mikelis Kaneps Avatar answered Sep 25 '22 02:09

Mikelis Kaneps


Splash screen it's bad practice, when it possible not to use it than please avoid using splash screen. You can read a some articles about this link1, link2.

But if need to show splash than use through creating a custom theme that overrides android:windowBackground, then replacing that custom theme with your standard theme before calling super.onCreate(). Here is tutorial of implementation and detailed description.

Assuming you have a theme called AppTheme, your launcher theme would be:

<style name="AppTheme.Launcher"> <item name="android:windowBackground">@drawable/launch_screen</item> </style>

Then apply your theme to your activity in your AndroidManifest.xml using android:theme="@style/AppTheme.Launcher".

The easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before super.onCreate() and setContentView():

public class MyMainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { // Make sure this is before calling super.onCreate setTheme(R.style.Theme_MyApp); super.onCreate(savedInstanceState); // ... } }

like image 44
Volodymyr Avatar answered Sep 21 '22 02:09

Volodymyr