Android 启动画面持续时间
Android Splash screen duration
我们使用启动画面在用户每次打开应用程序时显示公司徽标。目前,我们正在显示启动画面 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);
}
}
但是这个闪屏持续时间只是在团队中随机选择的。
我们有点知道启动画面通常并不是 Android 应用生态系统所鼓励的,但由于这是我们应用的需要,因此它被实现了。
我的问题:是否有任何标准Android guideline/best 实践来选择正确的启动画面持续时间?
Google 指南非常明确。
仅在必要时才使用启动画面。 (如果你没有任何东西可以展示给用户)它应该只在你有一些数据要展示之前是可见的。
如果您浏览 Google 个应用程序,您会在后面看到启动画面。
有很多更聪明的方法来为您的应用程序打上烙印。
您可以找到更多数据 here.
启动画面是一种不好的做法,如果可以不使用它,请避免使用启动画面。您可以阅读一些关于此的文章 link1, link2。
但如果需要显示启动画面而不是通过创建覆盖 android:windowBackground
的自定义主题来使用,则在调用 super.onCreate()
之前用您的标准主题替换该自定义主题。这里是tutorial的实现和详细的描述。
假设您有一个名为 AppTheme 的主题,您的启动器主题将是:
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
然后使用 android:theme="@style/AppTheme.Launcher".
将您的主题应用到 AndroidManifest.xml 中的 activity
转换回正常主题的最简单方法是在 super.onCreate() 和 setContentView() 之前调用 setTheme(R.style.AppTheme):
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);
// ...
}
}
更好的选择是使用带有自定义主题的启动画面 activity,启动主要内容 activity。有了这个,就不需要使用计时器,因为它会在应用程序准备就绪时切换到主要内容,同时显示主题内的图片。
这里是教程 - 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>
甚至可以将样式添加到应用程序,而无需使用单独的 activity。
社区接受的标准解决方案正在使用启动主题。
看看这个 post:http://saulmm.github.io/avoding-android-cold-starts
我们使用启动画面在用户每次打开应用程序时显示公司徽标。目前,我们正在显示启动画面 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);
}
}
但是这个闪屏持续时间只是在团队中随机选择的。 我们有点知道启动画面通常并不是 Android 应用生态系统所鼓励的,但由于这是我们应用的需要,因此它被实现了。
我的问题:是否有任何标准Android guideline/best 实践来选择正确的启动画面持续时间?
Google 指南非常明确。 仅在必要时才使用启动画面。 (如果你没有任何东西可以展示给用户)它应该只在你有一些数据要展示之前是可见的。 如果您浏览 Google 个应用程序,您会在后面看到启动画面。 有很多更聪明的方法来为您的应用程序打上烙印。 您可以找到更多数据 here.
启动画面是一种不好的做法,如果可以不使用它,请避免使用启动画面。您可以阅读一些关于此的文章 link1, link2。
但如果需要显示启动画面而不是通过创建覆盖 android:windowBackground
的自定义主题来使用,则在调用 super.onCreate()
之前用您的标准主题替换该自定义主题。这里是tutorial的实现和详细的描述。
假设您有一个名为 AppTheme 的主题,您的启动器主题将是:
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
然后使用 android:theme="@style/AppTheme.Launcher".
转换回正常主题的最简单方法是在 super.onCreate() 和 setContentView() 之前调用 setTheme(R.style.AppTheme):
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);
// ...
}
}
更好的选择是使用带有自定义主题的启动画面 activity,启动主要内容 activity。有了这个,就不需要使用计时器,因为它会在应用程序准备就绪时切换到主要内容,同时显示主题内的图片。
这里是教程 - 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>
甚至可以将样式添加到应用程序,而无需使用单独的 activity。
社区接受的标准解决方案正在使用启动主题。
看看这个 post:http://saulmm.github.io/avoding-android-cold-starts