ahmetvefa53
ahmetvefa53

Reputation: 611

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.

Upvotes: 1

Views: 2018

Answers (2)

Dayan
Dayan

Reputation: 8031

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.

Upvotes: 1

SebastienRieu
SebastienRieu

Reputation: 1512

use show method to display the toast.

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

Upvotes: 0

Related Questions