首页 > 解决方案 > 跳过了 172 帧!应用程序可能在其主线程上做了太多工作

问题描述

在我的 Java 项目中,只有用户登录和注册,其中只有按钮的活动。当我第二次运行模拟器时,我收到了这样的警告。当我想去注册页面时,它会发送到带有按钮的页面。或者用户登录页面第一次打开时没有打开。警报如下所示: 跳过 172 帧!应用程序可能在其主线程上做了太多工作。我是 Android 编程新手,如果您能提供帮助,我将不胜感激。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.geziproject">
   <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Geziproject">
        <activity android:name=".bos"/>
        <activity android:name=".kayitol" />
        <activity android:name=".kullanicigiris">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

kayitol.java

public class kayitol extends AppCompatActivity {
    private EditText txtAd, txtEmail, txtŞifre;
    private Button btnkayit;
    FirebaseAuth mFirebaseAuth;
    //DatabaseReference yol;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kayitol);
        mFirebaseAuth = FirebaseAuth.getInstance();
        txtAd = findViewById(R.id.txtad);
        txtEmail = findViewById(R.id.txtEmail);
        txtŞifre = findViewById(R.id.txtŞifre);
        btnkayit = findViewById(R.id.kayit);

        btnkayit.setOnClickListener(v -> {
            String email = txtEmail.getText().toString();
            String pwd = txtŞifre.getText().toString();
            if (email.isEmpty()) {
                txtEmail.setError("Lütfen email giriniz");
                txtEmail.requestFocus();
            } else if (pwd.isEmpty()) {
                txtŞifre.setError("Lütfen şifre giriniz");
                txtŞifre.requestFocus();
            } else if (email.isEmpty() && pwd.isEmpty()) {
                Toast.makeText(kayitol.this, "Bu alanlar boş bırakılamaz", Toast.LENGTH_LONG).show();
            } else if (!(email.isEmpty() && pwd.isEmpty())) {
                mFirebaseAuth.createUserWithEmailAndPassword(email, pwd).addOnCompleteListener(kayitol.this, task -> {
                    if (!task.isSuccessful()) {
                        Toast.makeText(kayitol.this, "Kayıt başarısız,tekrar deneyiniz", Toast.LENGTH_LONG).show();
                    } else {
                        Intent intent = new Intent(kayitol.this, bos.class);
                        startActivity(intent);
                    }
                });
            } else {
                Toast.makeText(kayitol.this, "Hata oluştu", Toast.LENGTH_LONG).show();
            }
        });
    }
}

kullanicigiris.java

public class kullanicigiris extends AppCompatActivity {
    Button btngiris;
    Button btnkayit;
    FirebaseAuth mFirebaseAuth;
    private EditText txtad;
    private EditText txtemail;
    private EditText txtsifre;
    private FirebaseAuth.AuthStateListener mAuthListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kullanicigiris);
        mFirebaseAuth = FirebaseAuth.getInstance();
        Button btngiris = findViewById(R.id.giris);
        Button btnkayit = findViewById(R.id.kayit);

        txtad = findViewById(R.id.txtad);
        txtemail = findViewById(R.id.txtemaili);
        txtsifre = findViewById(R.id.txtŞifre);
        
        mAuthListener = firebaseAuth -> {
            FirebaseUser mFirebaseUser = mFirebaseAuth.getCurrentUser();
            if (mFirebaseUser != null) {
                Toast.makeText(kullanicigiris.this, "giriş yaptın", Toast.LENGTH_LONG).show();
                Intent i = new Intent(kullanicigiris.this, bos.class);
                startActivity(i);
            } else {
                Toast.makeText(kullanicigiris.this, "lütfen giriş yapın", Toast.LENGTH_LONG).show();
            }
        };

        btngiris.setOnClickListener(v -> {
            String email = txtemail.getText().toString();
            String pwd = txtsifre.getText().toString();
            if (email.isEmpty()) {
                txtemail.setError("Lütfen email giriniz");
                txtemail.requestFocus();
            } else if (pwd.isEmpty()) {
                txtsifre.setError("Lütfen şifre giriniz");
                txtsifre.requestFocus();
            } else if (email.isEmpty() && pwd.isEmpty()) {
                Toast.makeText(kullanicigiris.this, "Bu alanlar boş bırakılamaz", Toast.LENGTH_LONG).show();
            } else if (!(email.isEmpty() && pwd.isEmpty())) {
                mFirebaseAuth.signInWithEmailAndPassword(email, pwd).addOnCompleteListener(kullanicigiris.this, task -> {
                    if (!task.isSuccessful()) {
                        Toast.makeText(kullanicigiris.this, "Giriş  başarısız ,tekrar deneyiniz", Toast.LENGTH_LONG).show();
                    } else {
                        txtad.setText("");
                        txtemail.setText("");
                        txtsifre.setText("");
                        startActivity(new Intent(kullanicigiris.this, bos.class));
                    }
                });
            } else {
                Toast.makeText(kullanicigiris.this, "Hata oluştu", Toast.LENGTH_LONG).show();
            }
        });

        btnkayit.setOnClickListener(v -> {
            Intent i = new Intent(kullanicigiris.this, kayitol.class);
            startActivity(i);
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mFirebaseAuth.addAuthStateListener(mAuthListener);

    }
}

bos.java

public class bos extends AppCompatActivity {

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

跑:

12/07 16:40:12: Launching 'app' on Pixel.
Install successfully finished in 2 s 552 ms.
$ adb shell am start -n "com.example.geziproject/com.example.geziproject.kullanicigiris" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 7342 on device 'emulator-5554'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ple.geziprojec: Not late-enabling -Xcheck:jni (already on)
I/ple.geziprojec: Unquickening 12 vdex files!
W/ple.geziprojec: Unexpected CPU variant for X86 using defaults: x86
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
W/ple.geziprojec: Verification of boolean com.google.android.gms.common.GoogleApiAvailabilityLight.isPlayServicesPossiblyUpdating(android.content.Context, int) took 251.962ms (19.84 bytecodes/s) (776B approximate peak alloc)
W/ple.geziprojec: Verification of com.google.android.gms.tasks.Task com.google.android.gms.common.GoogleApiAvailability.makeGooglePlayServicesAvailable(android.app.Activity) took 120.192ms (316.16 bytecodes/s) (1400B approximate peak alloc)
I/FirebaseInitProvider: FirebaseApp initialization successful
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/ple.geziprojec: Verification of void com.google.android.gms.common.api.internal.GoogleApiManager$zaa.<init>(com.google.android.gms.common.api.internal.GoogleApiManager, com.google.android.gms.common.api.GoogleApi) took 115.333ms (945.09 bytecodes/s) (3688B approximate peak alloc)
W/ple.geziprojec: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ple.geziprojec: Verification of void com.google.android.gms.common.api.internal.GoogleApiManager$zaa.onConnected(android.os.Bundle) took 141.826ms (246.78 bytecodes/s) (1264B approximate peak alloc)
W/ple.geziprojec: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10153; state: ENABLED
D/HostConnection: HostConnection::get() New Host Connection established 0xeaedfd50, tid 7393
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xeaeded90: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xeaeded90: ver 2 0 (tinfo 0xeb222df0) (first time)
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to fallback implementation
I/Gralloc4: mapper 4.x is not supported
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0xeaedfb20, tid 7393
D/goldfish-address-space: allocate: Ask for block of size 0x100
    allocate: ioctl allocate returned offset 0x3fcf6d000 size 0x2000
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
I/OpenGLRenderer: Davey! duration=976ms; Flags=1, IntendedVsync=1293927629619, Vsync=1293977629617, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1293986896900, AnimationStart=1293986963100, PerformTraversalsStart=1293987049900, DrawStart=1294410491800, SyncQueued=1294418169100, SyncStart=1294436241500, IssueDrawCommandsStart=1294436512100, SwapBuffers=1294778679200, FrameCompleted=1294922281100, DequeueBufferDuration=187900, QueueBufferDuration=733800, GpuCompleted=0, 
I/Choreographer: Skipped 61 frames!  The application may be doing too much work on its main thread.

标签: javaandroidfirebase

解决方案


通常,以低于 200 左右的数量跳过的帧往往只是在您的模拟器上滞后。这是意料之中的;模拟器很慢。在您当前的状态下,这可能是您可以放心忽略的问题。

您可以关闭计算机上其他不必要的程序,看看它是否会好转。无论如何,您可能会跳过几帧,但通常没问题。

只有当跳帧的数量变得足够大以至于严重影响实际硬件上的用户体验时,这个问题才是一个严重的问题。那将在 300+ 帧的范围内

有关详细信息,请查看Android UI:修复跳帧


推荐阅读