activity之间可以传String,Integer

不要拘泥与一种形式
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ActivityManagerService是负责监控应用程序的响应情况的服务,当应用程序出现ANR时,该服务会弹出ANR对话框。其ANR相关的源码如下: 1. 监控应用程序响应状态:ActivityManagerService会周期性地检测所有应用程序的响应状态,如果应用程序长时间未响应,就会触发ANR,代码如下: ``` private void checkAppTimeLimitLocked(ProcessRecord app) { // Check if the app has exceeded its time limits. if (app.notResponding) { return; // Don't kill the app if it is already not responding. } final boolean isSilentANR = mService.mDidDexOpt; final long now = SystemClock.uptimeMillis(); final long maxTime = isSilentANR ? mConstants.SANE_ANR_TIMEOUT : mConstants.ANR_TIMEOUT; final long timeSinceUnfrozen = now - app.lastStateTime; final boolean overTimeLimit = timeSinceUnfrozen > maxTime; if (DEBUG_ANR) { Slog.i(TAG, "checkAppTimeLimitLocked: " + app + " timeSinceUnfrozen=" + timeSinceUnfrozen + " maxTime=" + maxTime + " over=" + overTimeLimit); } if (overTimeLimit) { makeAppNotRespondingLocked(app, null, null, 0, "time limit exceeded", isSilentANR); } } ``` 2. 触发ANR:当应用程序长时间未响应时,ActivityManagerService会调用makeAppNotRespondingLocked方法触发ANR,代码如下: ``` void makeAppNotRespondingLocked(ProcessRecord app, String reason, String shortMsg, int flags, String message, boolean isSilentANR) { if (app.notResponding) { return; } mService.addErrorToDropBox("anr", app, app.processName, null, null, reason, message, null, null); ... // Show the ANR to the user. Message msg = Message.obtain(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("app", app); map.put("shortMsg", shortMsg); map.put("flags", flags); map.put("isSilentANR", isSilentANR); msg.obj = map; mHandler.sendMessage(msg); ... } ``` 3. 弹出ANR对话框:当应用程序出现ANR时,ActivityManagerService会通过Handler向主线程发送消息,弹出ANR对话框,代码如下: ``` private final class UiHandler extends Handler { public UiHandler() { super(mService.mHandler.getLooper()); } @Override public void handleMessage(Message msg) { switch (msg.what) { case SHOW_NOT_RESPONDING_UI_MSG: { HashMap<String, Object> data = (HashMap<String, Object>) msg.obj; ProcessRecord app = (ProcessRecord) data.get("app"); String shortMsg = (String) data.get("shortMsg"); int flags = (Integer) data.get("flags"); boolean isSilentANR = (Boolean) data.get("isSilentANR"); ... // Display the ANR dialog. mActivityManagerInternal.showAppErrorUi(app.pid, app.info.packageName, shortMsg, null, null, flags, isSilentANR); ... break; } ... } } } ``` 以上就是ActivityManagerService中ANR相关的源码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值