Android studio Log.i()无法记录for循环中的所有行

qojgxg4l  于 5个月前  发布在  Android
关注(0)|答案(1)|浏览(68)

我正在解决一些问题,并希望在for循环中检查列表项,希望看到所有项。最后我发现可以跳过项。我的测试如下:
1.在主活动按钮onClick,记录1000个项目,但它停止在495

btnSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (BuildConfig.DEBUG) {
                    //testing logging
                    for (int n=0; n<1000; n++)
                    {
                        Log.i(TAG, "Testing Log.i  "+n + "/"+1000);
                    }
                }
                /*
                Intent intent = new Intent(MainActivity.this, ConfigActivity.class);

                startActivity(intent);*/
            }
        });

字符串
结果在495处停止:

...
    2023-12-31 06:52:52.127  1826-1826  [dbg]MainActivity I  Testing Log.i  493/1000
    2023-12-31 06:52:52.127  1826-1826  [dbg]MainActivity I  Testing Log.i  494/1000
    2023-12-31 06:52:52.127  1826-1826  [dbg]MainActivity I  Testing Log.i  495/1000


1.在子屏幕上单击按钮,在finish()返回MainActivity之前,跳过随机项

2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  0/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  1/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  2/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  5/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  23/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  26/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  28/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  29/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  30/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  35/1000
        2023-12-31 06:46:23.811 29705-29705 [dbg]CreatePattern  I  Testing Log.i  37/1000
        ...


有人遇到过同样的情况吗?

ffx8fchx

ffx8fchx1#

这是一种正常的情况,当行必须以比系统处理它们的速度更快的速度写入logcat时,总是会发生这种情况(logcat没有队列,挂起的行被忽略)。如果你让循环变慢,例如使用额外的数学计算,如double d = Math.sin(n);),你会看到更多,也许已经是logcat中的所有n值。

相关问题