应用程序没有响应,为什么不显示 ANR 弹出窗口?

Application not responding, why doesn't ANR popup display?

我想测试 我的应用程序没有响应。下面代码中的按钮运行无限循环,但未显示 ANR 弹出窗口。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    Toast.makeText(this@MainActivity,"ahmet vefa saruhan",Toast.LENGTH_SHORT).show()
}

fun buttonClickec2( v : View) { //after button click
    while(true) {
        //Nothing to do, why doesn't ANR show?
    }
}

请仔细阅读问题。问题是关于 ANR 弹出窗口。

使用show方法显示toast。

Toast.makeText(this@MainActivity,"ahmet vefa saruhan",Toast.LENGTH_SHORT).show()

您试图通过无限循环故意显示 ANR 弹出对话框。

fun buttonClickec2( v : View) { //after button click
    while(true) {
        //Nothing to do, why doesn't ANR show?
    }
}

根据 Android 文档 here:

Android shows ANR dialogs for apps that take too long to process the broadcast message only if Show all ANRs is enabled in the device’s Developer options. For this reason, background ANR dialogs are not always displayed to the user, but the app could still be experiencing performance issues.