I need to reproduce Application Not Responding (ANR) dialogs from Activity and from BroadCastReceiver. I tried to create a simple button click:
public void makeANRClick(View view){
while (true);
}
With this code I reproduced ANR on emulator with android 2.3.7. Same code doesn't work on real device with the newest android versions (4+).
Another attempt was as follows:
public void onMakeANRClick(View view){
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
This doesn't help also. Any suggestions?
Have a look at StrictMode. And this video, too.
"StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them. "
Also you can check the dump state to check info about your process https://source.android.com/devices/input/diagnostics.html
I reproduce your code and then pull the 'dumpstate_app_anr.txt.gz' and this was the result
PID TID PR CPU% S VSS RSS PCY UID Thread Proc
15287 15287 0 83% R 227152K 25152K fg u0_a135 a.stackoverflow mx.syca.stackoverflow
07-03 08:46:12.454 1618 1636 I ActivityManager: Killing proc 12946:mx.syca.stackoverflow/u0a135: force stop
It took about 2 minutes to get the ANR dialog
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With