【问题标题】:Android splash screen is white in the beginning?Android启动画面一开始是白色的?
【发布时间】:2013-06-15 09:50:28
【问题描述】:

当我启动我的应用程序时,我会看到几秒钟的白屏,然后才会出现启动画面。

我想知道我的应用程序的大小是否会影响它(它是 17.7MB)。 还是因为我的测试设备太旧了(HTC Desire HD),里面的数据太多了?

或者这是正常行为? 或者问题出在我的代码中,如下所示...

清单的一部分:

    <activity android:name=".SplashView"
          android:noHistory="true"
          android:screenOrientation="portrait"
          android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" 
        android:windowSoftInputMode="adjustPan"
        android:configChanges="orientation" >
        <intent-filter >
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

飞溅活动:

public class SplashView extends SherlockActivity {
private final int SPLASH_DISPLAY_LENGHT = 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.splash_view);
    try {
        RefreshRatingsTask urt = new RefreshRatingsTask();
        urt.execute();
    } catch (Exception e) {
        // ignore
    }
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent mainIntent = new Intent(SplashView.this,
                    MainActivity.class);
            SplashView.this.startActivity(mainIntent);
            SplashView.this.finish();
        }

    }, SPLASH_DISPLAY_LENGHT);
}
}

谢谢

【问题讨论】:

  • 我认为这是旧设备+重应用程序的混合体。当我在摩托罗拉 Spice 上打开愤怒的小鸟时,这种情况曾经发生过 - 白屏大约 20 秒。

标签: android performance


【解决方案1】:
    RefreshRatingsTask urt = new RefreshRatingsTask();
    urt.execute();

这个异步任务似乎是罪魁祸首。它的操作可能需要一些时间,因此不会立即出现闪屏。将其注释掉并再次检查。
此外,在飞溅活动中做繁重的工作并不是一个好习惯。为其创建服务并在后台执行。

【讨论】:

  • 感谢您的回复。顺便说一句,RefreshRatingTask 扩展了 AsyncTask 所以它不应该是一个问题,因为它在单独的线程中运行。但是在注释掉之后,同样的问题..
  • 感谢您的反馈。是的,我知道这是一个异步任务。你在其他设备上测试过吗?模拟器?结果是否一样。
  • 是的.. 三星 S3 也有同样的问题。我想我必须弄清楚如何提高应用程序的速度并减小其大小
【解决方案2】:

Android 使用初始 Activity 的 Theme 来显示一个虚拟 Activity,同时将应用程序加载到内存中。

使您的应用程序更小将有助于减少等待时间,使用主题来设置启动画面的样式将使其不那么引人注目。

This blog post by Cyril Mottier 有更多详细信息。

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多