我是靠谱客的博主 友好时光,最近开发中收集的这篇文章主要介绍Android的广播队列,Android app启动流程,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

final int broadcastIntentLocked(ProcessRecord callerApp,

String callerPackage, Intent intent, String resolvedType,

IIntentReceiver resultTo, int resultCode, String resultData,

Bundle resultExtras, String[] requiredPermissions, int appOp, Bundle bOptions,

boolean ordered, boolean sticky, int callingPid, int callingUid, int userId) {

if (intent.getComponent() == null) {

if (userId == UserHandle.USER_ALL && callingUid == Process.SHELL_UID) {

for (int i = 0; i < users.length; i++) {

if (mUserController.hasUserRestriction(

UserManager.DISALLOW_DEBUGGING_FEATURES, users[i])) {

continue;

}

List registeredReceiversForUser = mReceiverResolver.queryIntent(intent, resolvedType, false, users[i]);

if (registeredReceivers == null) {

registeredReceivers = registeredReceiversForUser;

} else if (registeredReceiversForUser != null) {

registeredReceivers.addAll(registeredReceiversForUser);

}

}

} else {

registeredReceivers = mReceiverResolver.queryIntent(intent,resolvedType, false, userId);

}

}

while (ir < NR) {

if (receivers == null) {

receivers = new ArrayList();

}

receivers.add(registeredReceivers.get(ir));

ir++;

}

if ((receivers != null && receivers.size() > 0) || resultTo != null) {

BroadcastQueue queue = broadcastQueueForIntent(intent);

BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,

callerPackage, callingPid, callingUid, resolvedType,

requiredPermissions, appOp, brOptions, receivers, resultTo, resultCode,

resultData, resultExtras, ordered, sticky, false, userId);

r.enqueueTime = SystemClock.uptimeMillis();

boolean replaced = replacePending && queue.replaceOrderedBroadcastLocked(r);

if (!replaced) {

queue.enqueueOrderedBroadcastLocked(r);

queue.scheduleBroadcastsLocked();

}

} else {

if (intent.getComponent() == null && intent.getPackage() == null

&& (intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) {

addBroadcastStatLocked(intent.getAction(), callerPackage, 0, 0, 0);

}

}

return ActivityManager.BROADCAST_SUCCESS;

}

其实这个函数比较复杂的,我们删减来关键部分,看到黑体部分:

1、将intent所描述的发送的receiver在mReceiverResolver去找到;

2、当然接受者不仅仅是一个,有可能是多个。然后通过broadcastQueueForIntent 去拿到这个 queue;

3、然后queue调用相应的函数处理。

最后

以上就是友好时光为你收集整理的Android的广播队列,Android app启动流程的全部内容,希望文章能够帮你解决Android的广播队列,Android app启动流程所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部