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

问题描述

我是一名 Android 初学者,编写了一个简单的应用程序来测试网格视图。我在模拟器上执行应用程序并在运行窗口中显示运行消息。每当我单击按钮时,它都会显示

“……跳过了 70 帧!应用程序可能在其主线程上做了太多工作。”</p>

运行消息。我的问题是为什么运行窗口会显示该消息。是正常的还是不正常的?

我的源代码如下:

enter code here`package com.example.lulala.exgridview01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private GridView gridView;
    private int[] image = {
      R.drawable.plant1, R.drawable.plant2, R.drawable.plant3,
      R.drawable.plant4, R.drawable.plant5, R.drawable.plant6,
      R.drawable.plant7, R.drawable.plant8, R.drawable.plant9,
      R.drawable.plant10, R.drawable.plant11, R.drawable.plant12,
};
    private String[] imgText = {
           "plant1","plant2","plant3","plant4","plant5","plant6",
           "plant7","plant8","plant9","plant10","plant11","plant12"
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        List<Map<String,Object>> items = new ArrayList<>();
        for (int i = 0; i < image.length; i++){
            Map<String,Object> item = new HashMap<>();
            item.put("image",image[i]);
            item.put("text",imgText[i]);
            items.add(item);
        }
        SimpleAdapter adapter = new SimpleAdapter(this,items,R.layout.grid_item,   
               new String[]{"image","text"},new int[]{R.id.image,R.id.text});
        gridView = findViewById(R.id.main_gridview);
        gridView.setNumColumns(3);
        gridView.setAdapter(adapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int   
                      position, long id) {
                    Toast.makeText(MainActivity.this, " Choice: 
                       "+imgText[position],Toast.LENGTH_LONG).show();
                    }
          });
    }
}

运行窗口如下图所示:

08/12 13:46:50: Launching app
$ adb install-multiple -r -t /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/resources/instant-run/debug/resources-debug.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_0.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_5.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_1.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/dep/dependencies.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_8.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_3.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_2.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_4.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_9.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_6.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/split-apk/debug/slices/slice_7.apk /Users/lulala/AndroidStudioProjects/ExGridView01/app/build/intermediates/instant-run-apk/debug/app-debug.apk 
Split APKs installed
$ adb shell am start -n "com.example.lulala.exgridview01/com.example.lulala.exgridview01.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Waiting for process to come online
Connected to process 2914 on device Nexus_6_API_28 [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/la.exgridview0: Not late-enabling -Xcheck:jni (already on)
W/la.exgridview0: Unexpected CPU variant for X86 using defaults: x86
W/la.exgridview0: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10068(com.example.lulala.exgridview01) identical 10 lines
W/la.exgridview0: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/la.exgridview0: Verification of void com.android.tools.ir.server.Server.<init>(java.lang.String, android.content.Context) took 132.849ms
W/la.exgridview0: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/la.exgridview0: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
W/la.exgridview0: JNI critical lock held for 53.436ms on Thread[1,tid=2914,Runnable,Thread*=0xeb974000,peer=0x73a22760,"main"]
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xe79cd640, tid 2960
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
               android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/EGL_emulation: eglCreateContext: 0xe5985180: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xe5985180: ver 3 0 (tinfo 0xe59836e0)
I/Choreographer: Skipped 158 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xe5985180: ver 3 0 (tinfo 0xe59836e0)
I/OpenGLRenderer: Davey! duration=14060ms; Flags=0, IntendedVsync=143256734995, Vsync=145890068223, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=145900479118, AnimationStart=145900638744, PerformTraversalsStart=145900717608, DrawStart=145917488092, SyncQueued=145982042449, SyncStart=145984617369, IssueDrawCommandsStart=145984761951, SwapBuffers=153712375702, FrameCompleted=157319988695, DequeueBufferDuration=80000, QueueBufferDuration=5482000, 
I/OpenGLRenderer: Davey! duration=1051ms; Flags=0, IntendedVsync=158063467774, Vsync=158063467774, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=158068354187, AnimationStart=158068530330, PerformTraversalsStart=158068548390, DrawStart=158083973844, SyncQueued=158231144838, SyncStart=158243179453, IssueDrawCommandsStart=158244003412, SwapBuffers=158317220295, FrameCompleted=159126723311, DequeueBufferDuration=93000, QueueBufferDuration=468000, 
I/Choreographer: Skipped 57 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=1587ms; Flags=0, IntendedVsync=158230110721, Vsync=159180110683, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=159182195370, AnimationStart=159182263238, PerformTraversalsStart=159182268410, DrawStart=159182688099, SyncQueued=159186028517, SyncStart=159186064225, IssueDrawCommandsStart=159186187430, SwapBuffers=159188081253, FrameCompleted=159817779420, DequeueBufferDuration=269356000, QueueBufferDuration=2136000, 
I/Choreographer: Skipped 56 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=3354ms; Flags=0, IntendedVsync=165328242627, Vsync=166261575923, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=166272352984, AnimationStart=166272383637, PerformTraversalsStart=166273013513, DrawStart=166274315053, SyncQueued=166276475096, SyncStart=166277534365, IssueDrawCommandsStart=166277761222, SwapBuffers=166662844892, FrameCompleted=168683978150, DequeueBufferDuration=108000, QueueBufferDuration=20807000, 
I/Choreographer: Skipped 170 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=3934ms; Flags=1, IntendedVsync=166275904019, Vsync=169109237239, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=169119053142, AnimationStart=169119110686, PerformTraversalsStart=169272676122, DrawStart=169978922653, SyncQueued=169980961358, SyncStart=169983340048, IssueDrawCommandsStart=169983483331, SwapBuffers=169984275898, FrameCompleted=170212782068, DequeueBufferDuration=29462000, QueueBufferDuration=40703000, 
I/Choreographer: Skipped 66 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xe5985180: ver 3 0 (tinfo 0xe59836e0)
I/OpenGLRenderer: Davey! duration=1297ms; Flags=0, IntendedVsync=169121988469, Vsync=170221988425, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=170234924519, AnimationStart=170234987750, PerformTraversalsStart=170238398545, DrawStart=170254693108, SyncQueued=170256053997, SyncStart=170315148618, IssueDrawCommandsStart=170315275215, SwapBuffers=170316341432, FrameCompleted=170478422121, DequeueBufferDuration=91000, QueueBufferDuration=6982000, 
D/EGL_emulation: eglMakeCurrent: 0xe5985180: ver 3 0 (tinfo 0xe59836e0)
I/OpenGLRenderer: Davey! duration=1506ms; Flags=0, IntendedVsync=169121988469, Vsync=170221988425, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=170234924519, AnimationStart=170234987750, PerformTraversalsStart=170238398545, DrawStart=170481419790, SyncQueued=170487377732, SyncStart=170620834016, IssueDrawCommandsStart=170621281280, SwapBuffers=170622257415, FrameCompleted=170761842062, DequeueBufferDuration=2244000, QueueBufferDuration=20196000, 
I/Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=1650ms; Flags=1, IntendedVsync=171390729511, Vsync=171690729499, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=171692184776, AnimationStart=171706315802, PerformTraversalsStart=171706981970, DrawStart=172732183409, SyncQueued=172795785610, SyncStart=172795826236, IssueDrawCommandsStart=172795917974, SwapBuffers=172813553731, FrameCompleted=173041471134, DequeueBufferDuration=707000, QueueBufferDuration=10743000, 
I/Choreographer: Skipped 82 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xe5985180: ver 3 0 (tinfo 0xe59836e0)

标签: javaandroid

解决方案


对我来说,原因是在调试 AndroidManifest 中将“vmSafeMode”设置为“true”,我想它以某种方式针对模拟器进行了优化,但在真实设备上却减慢了速度


推荐阅读