What is ANR

ANR = Application Not Responding

ANR type:

  • Key Dispatch Timeout

Not response to an input event(eg: key press,screen touch) within (15 seconds or 8 seconds,default 5 seconds)

  • Broadcast Timeout

a broadcastReceiver hasn’t finished within 10 seconds

  • Service Timeout

Request service failed within 20 seconds

Reminder

  • if you choose “force to close ”,AMS will kill the process.
  • Keep the scene for get important info is very import.

ANR Essential:

Java process has main thread and main message queue(main thread = activity thread)
The Main Thread ,that is responsible for handling the ui events like Draw,Listen and receive the UI events.
Main thread will pick up message from main message queue and dispatch it as soon as possible.
Before main thread finish processing current message ,it can not pick up next one.
If main thread stuck with one message and fail to dispatch is in time, ANR will occur.

ANR key info

We need to know why main thread can not process the message in time?

  • Can not get CPU time to run
  • wait for some event but it donot happen in time?
  • Message handle flow is too complicated?

So need the follow files for analyze.

  • MTKLog saved in T card,include:

Aee_exp->db files(data/aee_exp)
MoblieLog->APLog_xxx_xxx->APLog
MdLog->MDLog_xxx_xxx->Modem Log
Netlog-> MDLog_xxx_xxx->Network Log

  • data/anr saved on the phone,include:

Trace.txt

Mobile Log:
you can get more info about anr from event log and main log:

  • The ANR time stamp
  • which process happens anr
  • which type of anr
  • more inof about the process before anr

LOG中搜索关键字:
anr
application is not responding
system_app_anr

Trace.txt
you can get callstack from the Trace.txt

Analyze ANR

在APLOG中搜索关键字:
anr
application is not responding

android核心技术之ANR分析(MTK)_第1张图片

android核心技术之ANR分析(MTK)_第2张图片

Example

  • Description:

IDLE界面进入图库,打开大量的图片,选择条目,点击几张图片,按HOME键,再从IDLE界面进入图库,点击图片,弹出图库没有响应。

  • Analyze:

(1)find anr time,process ID,ANT type
在APLOG中搜索关键字:
anr
application is not responding
system_app_anr

(2)Check CPU usage
(3)check Trace.txt,mapping process id and time stamp.
最后发现是在主线程中执行了耗时操作query数据库,导致ANR
(4)find more info from main and event log to check main thread.
最后确认是:
main thread are busy query db database all the time.

Need MTK help

提供有效的LOG:
-MTKLog saved in T card,include:
Aee_exp->db files
MoblieLog->APLog_xxx_xxx->APLog
MdLog->MDLog_xxx_xxx->Modem Log
Netlog-> MDLog_xxx_xxx->Network Log
-data/anr saved on the phone,include:
Trace.txt
最好是提供ENG的LOG,ENG会提供了更多的信息。

常见导致ANR的原因:

  1. 数据库操作I/O被阻塞
    iowait、ContentResolver.query、onPostExecute
  2. 在UI线程进行网络数据的读写
  3. 内存不足导致block在创建bitmap上
    atdalvik.system.VMRuntime.trackExternalAllocation(NativeMethod)
    atandroid.graphics.Bitmap.createBitmap(Bitmap.java:468)
  4. 程序异常退出,uncausedexception (Fatal)
  5. 程序强制关闭,ForceClosed (简称FC) (Fatal)
  6. 通过搜索ANR定位问题

解决ANR的方法:

  • 不要让主线程干耗时的工作
  • 不要让其他线程阻塞主线程的执行

参考资料

1.如何分析解决Android ANR
http://blog.csdn.net/dadoneo/article/details/8270107

2.Android ANR分析与总结
http://blog.csdn.net/androiddevelop/article/details/49515903

3.Android ANR分析
http://blog.csdn.net/yxz329130952/article/details/50087731

4.Application Not Responding(ANR) Analyze
MediaTek On-Line > eCourse Home > SW > ALPS > Common Framework

更多相关文章

  1. android加载大图片
  2. Android之Glide(非常好用的图片加载框架)
  3. Android加载Gif图片的一般方法:Movie实现
  4. Android九宫格图片(9.png)的讲解与制作
  5. Android内核与主线linux内核的比较(Android对Linux内核的改动你知
  6. android 图片处理 resize 探秘(图片缩放、压缩问题)
  7. Android视频图片缩略图的获取
  8. [Android] Json格式解析和文字图片传输

随机推荐

  1. android:自定义长按/长点击事件
  2. adb shell 是什么,如何进入?
  3. android-样式和主题(style&theme)
  4. android 反编译(转)
  5. This view is not constrained verticall
  6. android ListView和GridView拖拽移位具体
  7. Android 本地广播LocalBroadcastManager
  8. Android AS平台jni环境配置
  9. Android Studio中添加Permission权限的步
  10. Android相机相册的调用,图片的存储删除