1

I am reading ANR. Most of things make sense to me but i can not understand that if Main thread is blocked then How OS create a Dialog in same process and show it on screen . From the Documentation:

An ANR will be triggered for your app when one of the following conditions occur:

1. While your activity is in the foreground, your app has not responded to an input event or BroadcastReceiver (such as key press or screen touch events) within 5 seconds.

2. While you do not have an activity in the foreground, your BroadcastReceiver hasn't finished executing within a considerable amount of time.

i.e The main thread is in a deadlock with another thread So how the OS manage to show a dialog . Cause i think we can only show dialog from a main thread. Please correct me if i am wrong and let me know the process of ANR dialog.
Any explanation will be really appreciated. Thx

ADM
  • 20,406
  • 11
  • 52
  • 83
Diaz diaz
  • 284
  • 1
  • 7
  • 21

1 Answers1

1

It's because it's not your app that is responsible for showing the dialog. The system handles it. From the documentation

If the app is in the foreground, the system displays a dialog to the user

So when you app is ANR, an external "app" (or intent if you will), will handles the popping of the dialog that allows you to terminate the ANR app...

Also, read this to understand the difference between ANR and crash

Jason Krs
  • 704
  • 2
  • 9
  • 30
  • So you mean the `Dialog` open from a `Context` of another app(System App) ? – Diaz diaz Mar 22 '18 at 08:02
  • Yes. It's a `system dialog`... It's raised by the OS itself. Read this [answer](https://stackoverflow.com/questions/4385323/change-custom-dialog-of-anrapplication-not-responding-dialog-android) – Jason Krs Mar 22 '18 at 08:06
  • There is a special Intent to be listening (i.e. broadcast listener) if you want to manually handle (mostly close) a system dialog. It's called [ACTION_CLOSE_SYSTEM_DIALOGS](https://developer.android.com/reference/android/content/Intent.html#ACTION_CLOSE_SYSTEM_DIALOGS) – Jason Krs Mar 22 '18 at 08:09