Android ANR梳理

ANR(Application Not responding),是指應用程序未響應,Android系統對於一些事件需要在一定的時間範圍內完成,如果超過預定時間能未能得到有效響應或者響應時間過長,都會造成ANR。一般地,這時往往會彈出一個提示框,告知用戶當前xxx未響應,用戶可選擇繼續等待或者Force Close。

ANR主要有4類:

  • Service Timeout:

對於前臺服務,則超時爲SERVICE_TIMEOUT = 20s;

對於後臺服務,則超時爲SERVICE_BACKGROUND_TIMEOUT = 200s

  • BroadcastQueue Timeout

對於前臺廣播,則超時爲BROADCAST_FG_TIMEOUT = 10s;

對於後臺廣播,則超時爲BROADCAST_BG_TIMEOUT = 60s

  • ContentProvider Timeout:內容提供者,在publish過超時10s;

ContentProvider 超時爲CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10s. 這個跟前面的Service和BroadcastQueue完全不同, 由Provider進程啓動過程相關.

  • InputDispatching Timeout: 
  1. 無窗口, 有應用:Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
  2. 窗口暫停: Waiting because the [targetType] window is paused.
  3. 窗口未連接: Waiting because the [targetType] window’s input channel is not registered with the input dispatcher. The window may be in the process of being removed.
  4. 窗口連接已死亡:Waiting because the [targetType] window’s input connection is [Connection.Status]. The window may be in the process of being removed.
  5. 窗口連接已滿:Waiting because the [targetType] window’s input channel is full. Outbound queue length: [outboundQueue長度]. Wait queue length: [waitQueue長度].
  6. 按鍵事件,輸出隊列或事件等待隊列不爲空:Waiting to send key event because the [targetType] window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: [outboundQueue長度]. Wait queue length: [waitQueue長度].
  7. 非按鍵事件,事件等待隊列不爲空且頭事件分發超時500ms:Waiting to send non-key event because the [targetType] window has not finished processing certain input events that were delivered to it over 500ms ago. Wait queue length: [waitQueue長度]. Wait queue head age: [等待時長].

http://gityuan.com/2016/07/02/android-anr/

http://gityuan.com/2017/01/01/input-anr/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章