简体   繁体   中英

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

I want to test my application which is not responding. The button in the code below runs an infinite loop but the ANR popup doesn't show.

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?
    }
}

Please read question carefully. The question is about the ANR popup.

You are trying to purposely display the ANR Popup dialog by causing an infinite loop.

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

As per Android documentation 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.

use show method to display the toast.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM