Android 启动画面持续时间

AAD*_*ing 4 android timer splash-screen

每次用户打开应用程序时,我们都使用启动画面来显示公司徽标。目前,我们正在显示启动画面 3 秒。

下面是代码:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这个闪屏持续时间只是在团队中随机选择的。我们有点知道在 Android 应用生态系统中,启动画面通常并不是那么鼓励,但由于这是我们应用的需要,因此它被实现了。

我的问题:是否有任何标准的 Android 指南/最佳实践来选择正确的启动画面持续时间?

Mik*_*eps 8

更好的选择是使用带有自定义主题的启动画面活动,以启动主要内容活动。有了这个,就不需要使用计时器,因为它会在应用程序准备好时切换到主要内容,同时显示主题内的图片。

这是如何做到这一点的教程 - https://www.bignerdranch.com/blog/splash-screens-the-right-way/

教程的主要部分:

<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>
Run Code Online (Sandbox Code Playgroud)

甚至可以将样式添加到应用程序中,而无需使用单独的活动。