为什么我的应用程序在第一次运行时启动速度非常慢(10s +),在Android 5.0上只显示白屏?

时间:2016-05-09 23:18:45

标签: android performance android-studio android-gradle android-5.0-lollipop

我有一个新创建的应用程序(内置于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

主要活动:

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();
        ****/
    }

摇篮

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"

}

2 个答案:

答案 0 :(得分:22)

这是因为Instant Run需要一段时间才能加载。空白/白色屏幕将在生产版本中消失。

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

您可以禁用“即时运行”,或者只是意识到您的生产版本不会出现此空白屏幕。

类似的问题:Android Studio 2.0 - pause/white screen on App first run

答案 1 :(得分:5)

这是因为InstantRun功能,它只发生在debug-builds中。

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