How to play non-responsive (ANR) application from Activity and from BroadcastReceiver

I need to play Application Not Response (ANR) dialogs from Activity and from BroadCastReceiver. I tried to create a simple click on a button:

public void makeANRClick(View view){ while (true); } 

With this code, I reproduced ANR on an emulator using android 2.3.7. The same code does not work on a real device with the latest versions of Android (4+).

Another attempt was as follows:

 public void onMakeANRClick(View view){ try { Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } } 

That doesn't help either. Any suggestions?

+7
android android-anr-dialog
source share
4 answers

Take a look at StrictMode . And this video too.

"StrictMode is a developer tool that detects what you accidentally do and draws them to your attention so you can fix them."

+1
source share

You can also check the status of the dump to check the information about your process https://source.android.com/devices/input/diagnostics.html

I play your code and then pull out 'dumpstate_app_anr.txt.gz' and that 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: stopping the effort

It took about 2 minutes to open the ANR dialog

Hope this helps

+1
source share

Keyword multithreading . Please read this topic http://developer.android.com/training/articles/perf-anr.html There is also no way to manage user interface components in Broadcast Reciever because it is not a user interface component. There is also an option in development options called "Show All ANR"

0
source share

I really think the best way to do ANR in java (dalvik) is to do an absurd amount of computation, including function calls.

Perhaps something similar to:

 Integer useless = 0; for (i=2147483648;i<2147483647;i++){ useless = Math.random() * Math.random() * Math.random() * Math.random(); } 

This, at least, will cause some delay and ANR for weaker systems.

0
source share

All Articles