我的Android应用启动太慢(大约10秒)

时间:2016-08-12 19:41:54

标签: android android-activity

首次启动应用时,会打开LoginActivity,下次启动时会打开MainActivityLoginActivity只需要记住用户名等。其他所有内容都在MainActivity

所以LoginActivity启动太慢了。请帮助优化应用程序以更快地启动它。

这是我的LoginActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    notFirstInit();

    spinner = (AppCompatSpinner) findViewById(R.id.spinner);
    editText = (EditText) findViewById(R.id.editText);
    button = (Button) findViewById(R.id.login_button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            name = editText.getText().toString();
            group = spinner.getSelectedItem().toString();

            saveUserData();

            startMainActivity();
            finish();
        }
    });
}

private void saveUserData() {
    editor = settings.edit();
    editor.putString("name", name);
    editor.putString("group", group);
    editor.apply();
}

private void notFirstInit() {
    settings = getSharedPreferences("settings", Context.MODE_PRIVATE);

    if (settings.getBoolean("activity_executed", false)) {
        startMainActivity();
        finish();
    } else {
        editor = settings.edit();
        editor.putBoolean("activity_executed", true);
        editor.apply();
    }
}

private void startMainActivity() {
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
}

您可以看到在logcat中启动需要多长时间:

08-13 00:07:12.500 6996-6996/uz.triplet.tuitguide W/System: ClassLoader referenced unknown path: /data/app/uz.triplet.tuitguide-1/lib/arm
08-13 00:07:21.927 6996-6996/uz.triplet.tuitguide W/System: ClassLoader referenced unknown path: /data/app/uz.triplet.tuitguide-1/lib/arm
08-13 00:07:21.929 6996-6996/uz.triplet.tuitguide I/LoadedApk: No resource references to update in package common
08-13 00:07:21.930 6996-6996/uz.triplet.tuitguide I/LoadedApk: No resource references to update in package com.chummy.jezebel.material.dark.regression
08-13 00:07:22.295 6996-7370/uz.triplet.tuitguide D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false

                                                                    [ 08-13 00:07:22.310  6996: 6996 D/         ]
                                                                    GPU monitor inactive - could not find libgpumonitor.so [(null)] or not enabled (debug.egl.hw.gpumonitor = 0)
08-13 00:07:22.359 6996-7370/uz.triplet.tuitguide D/libEGL: loaded /vendor/lib/egl/libGLES_vc4.so
08-13 00:07:22.407 6996-7370/uz.triplet.tuitguide I/OpenGLRenderer: Initialized EGL, version 1.4
08-13 00:07:22.410 6996-7370/uz.triplet.tuitguide W/egl_server: Allocating storage 1x1 surface type 0x1
08-13 00:07:22.421 6996-7370/uz.triplet.tuitguide W/khrn_client: init_window num_buffers 3 min undequeued buffers 1
08-13 00:07:22.422 6996-7370/uz.triplet.tuitguide W/khrn_client: init_window window 0x43747af8, 480x800 hintTransform 0x0 do_pre 1

UPD:我不知道为什么,但是当我使用Build - >建立新的APK时Build APK应用程序立即打开。运行应用程序点击按钮Run

有什么问题

0 个答案:

没有答案