为什么我的应用程序一开始 运行 启动得非常慢 (10s+),在 android 5.0 上只显示白屏?

Why does my App start incredibly slow (10s+) at first run, showing only white screen on android 5.0?

我有一个新创建的应用程序(内置于 android studio 2.0),有一些活动。

当我在我的 Android 4.3(注 2)设备上测试它时,它在全新安装后启动得很好而且很快,反过来在我的三星 galaxy S4 和 android 5.0 上使用相同的应用程序,仅显示白屏时挂起约 10-15 秒。

为了确保我已经从 android studio 中拔掉它并注释掉了我的 MainActivity 中的几乎所有方法,但这没有什么区别,我在 10 秒后启动安装或清除应用缓存后。

我真的很关心这个问题,这真的会损害我的应用程序的用户体验。

有什么问题吗?

Logcat:

05-10 02:07:14.266 26036-26631/com.cerculdivelor I/GMPM: App measurement is starting up
05-10 02:07:14.747 26036-26036/com.cerculdivelor W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-10 02:07:14.867 26036-26036/com.cerculdivelor D/Activity: performCreate Call secproduct feature valuefalse
05-10 02:07:14.867 26036-26036/com.cerculdivelor D/Activity: performCreate Call debug elastic valuetrue
05-10 02:07:14.907 26036-26036/com.cerculdivelor I/LOGTAG: Table has been created!
05-10 02:07:14.967 26036-26650/com.cerculdivelor D/OpenGLRenderer: Render dirty regions requested: true
05-10 02:07:15.007 26036-26649/com.cerculdivelor I/Timeline: Timeline: Activity_launch_request id:com.cerculdivelor time:111211793
05-10 02:07:15.127 26036-26645/com.cerculdivelor I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-10 02:07:15.127 26036-26645/com.cerculdivelor I/System.out: (HTTPLog)-Static: isShipBuild true
05-10 02:07:15.127 26036-26645/com.cerculdivelor I/System.out: (HTTPLog)-Thread-62285-755755249: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
05-10 02:07:15.127 26036-26645/com.cerculdivelor I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-10 02:07:15.137 26036-26645/com.cerculdivelor I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
05-10 02:07:15.147 26036-26650/com.cerculdivelor I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
                                                               OpenGL ES Shader Compiler Version: E031.25.03.06
                                                               Build Date: 01/24/15 Sat
                                                               Local Branch: AF11_RB1_AU15
                                                               Remote Branch: 
                                                               Local Patches: 
                                                               Reconstruct Branch: 
05-10 02:07:15.147 26036-26650/com.cerculdivelor I/OpenGLRenderer: Initialized EGL, version 1.4
05-10 02:07:15.197 26036-26650/com.cerculdivelor D/OpenGLRenderer: Enabling debug mode 0
05-10 02:07:15.417 26036-26036/com.cerculdivelor I/LOGTAG: Returned0rows
05-10 02:07:15.417 26036-26036/com.cerculdivelor I/LOGTAG: Returned0rows
05-10 02:07:15.988 26036-26051/com.cerculdivelor I/art: Background sticky concurrent mark sweep GC freed 40699(4MB) AllocSpace objects, 12(383KB) LOS objects, 0% free, 49MB/49MB, paused 1.007ms total 161.285ms
05-10 02:07:16.168 26036-26043/com.cerculdivelor W/art: Suspending all threads took: 5.249ms
05-10 02:07:16.228 26036-26036/com.cerculdivelor D/Activity: performCreate Call secproduct feature valuefalse
05-10 02:07:16.228 26036-26036/com.cerculdivelor D/Activity: performCreate Call debug elastic valuetrue
05-10 02:07:16.238 26036-26036/com.cerculdivelor I/Choreographer: Skipped 44 frames!  The application may be doing too much work on its main thread.
05-10 02:07:17.349 26036-26036/com.cerculdivelor I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@4e1915e time:111214133
05-10 02:07:17.349 26036-26036/com.cerculdivelor I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2d342603 time:111214133
05-10 02:07:17.369 26036-26036/com.cerculdivelor V/ActivityThread: updateVisibility : ActivityRecord{10b472f8 token=android.os.BinderProxy@2d342603 {com.cerculdivelor/com.cerculdivelor.MainActivity}} show : false
05-10 02:07:30.622 26036-26036/com.cerculdivelor I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@4e1915e time:111227400
05-10 02:08:36.286 26036-26036/com.cerculdivelor V/ActivityThread: updateVisibility : ActivityRecord{1e1f9137 token=android.os.BinderProxy@4e1915e {com.cerculdivelor/com.cerculdivelor.SplashActivity}} show : true

主要Activity:

public class MainActivity extends AppCompatActivity implements View.OnClickListener, HttpConActivity.downloadListener {

    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    private BroadcastReceiver mRegistrationBroadcastReceiver;
    private boolean isReceiverRegistered;
    CallbackManager callbackManager;
    private AccessTokenTracker accessTokenTracker;
    private List<ProductsGetterSetter> products;
    private SQLiteDataSource datasource;
    private TextView toolbarTitle;
    private String fbId;
    private String name;
    private TextView notifBubbleText;
    private TextView inboxBubbleText;
    private ArrayList<NotificationSetter> notifications;
    private SharedPreferences preferences;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
        toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
        setSupportActionBar(toolbar);

        /**** 
TextView title = (TextView) findViewById(R.id.toolbar_title);
        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Baron.otf");
        title.setTypeface(tf);

        TextView feedTv = (TextView) findViewById(R.id.feedTv);
        feedTv.setOnClickListener(this);
        TextView shopTv = (TextView) findViewById(R.id.shopTv);
        shopTv.setOnClickListener(this);
        TextView sellTv = (TextView) findViewById(R.id.sellTv);
        sellTv.setOnClickListener(this);
        TextView likesTv = (TextView) findViewById(R.id.likesTv);
        likesTv.setOnClickListener(this);
        TextView myShopTv = (TextView) findViewById(R.id.myShopTv);
        myShopTv.setOnClickListener(this);


        // Send crash report if exists
        if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
            Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
        }

        ****/

    }


    @Override
    protected void onResume() {
        super.onResume();

       /****
        datasource = new SQLiteDataSource(this);
        datasource.open();

        preferences = getSharedPreferences("user", MODE_PRIVATE);
        if (preferences.getString("fbId", "").equals("")) {
            promtForLogin();
        } else {
            initialiseApp();
        }

        this.invalidateOptionsMenu();
        ****/
    }

Gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.cerculdivelor"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.android.support:cardview-v7:23.0.+'
    compile 'com.android.support:recyclerview-v7:23.0.+'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    compile "com.google.android.gms:play-services-gcm:8.3.0"

}

这是因为 Instant Run 加载需要一段时间。 blank/white 屏幕将在生产版本中消失。

我不确定为什么 Instant 运行 需要这么长时间才能加载。如果您查看应用程序的内部缓存目录,您会看到很多 dex 文件。几天前这里有一篇关于 Instant 运行 如何工作的文章:https://medium.com/google-developers/instant-run-how-does-it-work-294a1633367f#.ntl30mbe2

您可以禁用 Instant 运行 或者只是注意您的生产版本不会有这个空白屏幕。

类似问题:

这是因为 InstantRun 功能,它只发生在调试版本中。

如果您想停止使用 InstantRun,请转到“设置”>“构建、执行、开发”>“InstantRun”,然后取消选中所有并应用。