当前位置:网站首页>Anr questions often asked in Android interviews
Anr questions often asked in Android interviews
2022-07-28 23:07:00 【ZZ White Dragon】
1.ANR Definition
Android The main thread of the application has been blocked for too long , Trigger "Application not Responding"(Anr) Error of . If the application is in the foreground , There will be pop ups .
2.ANR What happened
1. Time consuming operation of main line
2. The main thread is synchronously locked by the sub thread lock
3. The main thread is binder End to end blocking
4.binder Threads are stained
5. No system resources available
3.ANR Several types of
1.Service TimeOut Overtime
Reason for timeout :
In the implementation of the service life cycle approach :oncreate ,onstart onbind It's time-out
Timeout time : Front desk service 20s, Background services 200s
2.BroadCast TimeOut Broadcast timeout
Reason for timeout :
At the appointed time ,onReceive Method execution timed out
Timeout time : The front desk 10s, backstage 60s
3.InputDispatching Timeout
Input event timeout , If you click , No response to touch event
Timeout time :5s
ServiceTimeout Trigger mechanism
bumpServiceExecutingLocked(); Bury a bomb , The corresponding life cycle is not completed within the corresponding time , will anr, If it is finished, it will removemsg
send out
void scheduleServiceTimeoutLocked(ProcessRecord proc) {
if (proc.executingServices.size() == 0 || proc.thread == null) {
return;
}
Message msg = mAm.mHandler.obtainMessage(
ActivityManagerService.SERVICE_TIMEOUT_MSG);
msg.obj = proc;
mAm.mHandler.sendMessageDelayed(msg,
proc.execServicesFg ? SERVICE_TIMEOUT : SERVICE_BACKGROUND_TIMEOUT);
}
Handle SERVICE_TIMEOUT_MSG news
com.android.server.am.ActivityManagerService#SERVICE_TIMEOUT_MSG
case SERVICE_TIMEOUT_MSG: {
mServices.serviceTimeout((ProcessRecord)msg.obj);
} break;
// The first scene in the log :Timeout executing service
Slog.w(TAG, "Timeout executing service: " + timeout);
StringWriter sw = new StringWriter();
PrintWriter pw = new FastPrintWriter(sw, false, 1024);
pw.println(timeout);
timeout.dump(pw, " ");
pw.close();
mLastAnrDump = sw.toString();
mAm.mHandler.removeCallbacks(mLastAnrDumpClearer);
mAm.mHandler.postDelayed(mLastAnrDumpClearer, LAST_ANR_LIFETIME_DURATION_MSECS);
anrMessage = "executing service " + timeout.shortInstanceName;
BroadCast Timeout Trigger mechanism :
The broadcast is divided into : Serial , parallel
The broadcast that caused the timeout is Serial radio broadcast :
Orderly broadcasting of dynamic registration
Static registration broadcast
2.ANR Positioning process
1. adopt logcat see ANR in see cpu Information and system load
apk Package name , Process number , Trigger ANR Why , The system is happening ANR For each application of the time period cpu usage
Such as input Overtime ,ANR According to the timeout , Push forward 5s, Use application is not responding Filter , Filter monkey journal
2. find anr Of log journal , Check the main thread main Of trace Log information
/data/anr
3. Location occurrence ANR Specific time period
4. Check ANR The state of the system during the occurrence period
3. avoid ANR Methods : Reduce the time-consuming operation of the main thread
1.ServiceTimeout
avoid application oncreate Time consuming
avoid service The life cycle takes time
have access to IntentService
2.BroadCastTimeout
have access to IntentService
3.InputDispatching Timeout
Avoid time-consuming main threads
4. Reasonable performance optimization can also avoid
1. avoid while or ondraw in new object
2. Use object pool Android.util.Pools
3. Check for extra background pictures , Especially the background picture of the parent layout
4. Reduce layout levels :constrainlayout,merge
5. Delay loading layout viewstub
4.ANR Detection tools
blockcanary
strictmode
leakcanary
边栏推荐
- Is 1E3 a floating point number?
- Wheel 7: TCP client
- There are four ways for Nacos to configure hot updates and multiple ways to read project configuration files, @value, @refreshscope, @nacosconfigurationproperties
- Wheel 6: qserialport serial port data transceiver
- 投资1450亿欧元!欧盟17国宣布联合发展半导体技术
- c语言进阶篇:指针(三)
- Invest 145billion euros! EU 17 countries announce joint development of semiconductor technology
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to
- [3D target detection] 3dssd (I)
- This year, MediaTek 5g chip shipments are expected to reach 50million sets!
猜你喜欢

Cnpm installation steps

CGLIb 创建代理

Shell script foundation - shell operation principle + variable and array definitions

No code development platform management background tutorial

Yolov5 improvement 4: add ECA channel attention mechanism

A new paradigm of distributed deep learning programming: Global tensor
![[3D target detection] 3dssd (I)](/img/84/bcd3fe0ba811ea79248a5f50b15429.png)
[3D target detection] 3dssd (I)

can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory

RouYi-Cloud平台 ---项目的启动、登录功能是怎么实现的、怎么样创建新模块

PCA learning
随机推荐
Torch.fft.fft 2. () error reporting problem solution
Paper reading: deep forest / deep forest /gcforest
轮子六:QSerialPort 串口数据 收发
Improvement 13 of yolov5: replace backbone network C3 with lightweight network efficientnetv2
The industry's first cloud native security detection dual model! Safety dog heavyweight report appears at the digital China Construction Summit
《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》
Xshell7, xftp7 personal free version official download, no need to crack, no activation, download and use
Summary of common formula notes for solving problems in Higher Mathematics
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
Target detection notes fast r-cnn
DirectX修复工具下载(exagear模拟器数据包在哪里)
[3D target detection] 3dssd (I)
There are four ways for Nacos to configure hot updates and multiple ways to read project configuration files, @value, @refreshscope, @nacosconfigurationproperties
A new MPLS note from quigo, which must be read when taking the IE exam ---- quigo of Shangwen network
ValueError: Using a target size (torch.Size([64])) that is different to the input size (torch.Size([
Improvement 14 of yolov5: replace the backbone network C3 with the lightweight network GhostNet
The safety dog has been selected into many details of cloud security panorama 2.0
Servlet的使用手把手教学(一)
Sqlilabs-3 (entry notes)
Target detection notes SSD