android登录注册跳转的代码_Android开发代码

android登录注册跳转的代码_Android开发代码1.用户接口registerReceiverframeworks/base/core/java/android/content/ContextWrapper.java  publicIntentregisterReceiver(BroadcastReceiverreceiver,IntentFilterfilter){    returnmBase.registerRe…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

1. 用户接口registerReceiver

frameworks/base/core/java/android/content/ContextWrapper.java

    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {

        return mBase.registerReceiver(receiver, filter);

    }

frameworks/base/core/java/android/app/ContextImpl.java

    @Override

    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {

        return registerReceiver(receiver, filter, null, null);

    }

    @Override

    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,

            String broadcastPermission, Handler scheduler) {

        return registerReceiverInternal(receiver, getUserId(),

                filter, broadcastPermission, scheduler, getOuterContext(), 0);

    }

    @Override

    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,

            String broadcastPermission, Handler scheduler, int flags) {

        return registerReceiverInternal(receiver, getUserId(),

                filter, broadcastPermission, scheduler, getOuterContext(), flags);

    }

class ContextImpl extends Context {

……

 

@Override

public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {

return registerReceiver(receiver, filter, null, null);

}

 

@Override

public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,

String broadcastPermission, Handler scheduler) {

return registerReceiverInternal(receiver, filter, broadcastPermission,

scheduler, getOuterContext());

}

 

private Intent registerReceiverInternal(BroadcastReceiver receiver,

IntentFilter filter, String broadcastPermission,

Handler scheduler, Context context) {

IIntentReceiver rd = null;

if (receiver != null) {


// mPackageInfo是一个LoadedApk实例,它是用来负责处理广播的接收的
// context 是通过调用函数getOuterContext得到的


if (mPackageInfo != null && context != null) {

if (scheduler == null) {

// mMainThread.getHandler来获得一个Handler了,

                                        //这个Hanlder是后面用来分发ActivityManagerService发送过的广播用的。

// 这里的成员变量mMainThread是一个ActivityThread实例

scheduler = mMainThread.getHandler();

}

rd = mPackageInfo.getReceiverDispatcher(

receiver, context, scheduler,

mMainThread.getInstrumentation(), true);

} else {

……

}

}

try {

   final Intent intent = ActivityManager.getService().registerReceiver(

           mMainThread.getApplicationThread(), mBasePackageName, rd, filter,

           broadcastPermission, userId, flags);

   if (intent != null) {

       intent.setExtrasClassLoader(getClassLoader());

       intent.prepareToEnterProcess();

   }

   return intent;

} catch (RemoteException e) {

return null;

}

}

 

……

 

}

// BroadcastReceiver

frameworks/base/core/java/android/content/BroadcastReceiver.java

// getHandler()

public final class ActivityThread {

……

final H mH = new H();

 

private final class H extends Handler {

……

 

public void handleMessage(Message msg) {

……

 

switch (msg.what) {

……

}

 

……

}

 

……

 

}

……

 

final Handler getHandler() {

return mH;

}

……

}

// 

frameworks/base/core/java/android/app/LoadedApk.java

    public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r,

            Context context, Handler handler,

            Instrumentation instrumentation, boolean registered) {

        synchronized (mReceivers) {

            LoadedApk.ReceiverDispatcher rd = null;

            ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = null;

            if (registered) {


// ArrayMap<Context, ArrayMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers = new ArrayMap<>();
        //由context获得ArrayMap<BroadcastReceiver, ReceiverDispatcher>>
//由BroadcastReceiver获得ReceiverDispatcher


                map = mReceivers.get(context);

                if (map != null) {

                    rd = map.get(r);

                }

            }

            if (rd == null) {

                rd = new ReceiverDispatcher(r, context, handler, instrumentation, registered);

                if (registered) {

                    if (map == null) {

                        map = new ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>();

                        mReceivers.put(context, map);

                    }

                    map.put(r, rd);

                }

            } else {

                rd.validate(context, handler);

            }

            rd.mForgotten = false;


   //获得后就会把它传给ActivityManagerService,以便接收广播

            return rd.getIIntentReceiver();

        }

    }

    static final class ReceiverDispatcher {


//InnerReceiver实例,这是一个Binder对象,实现了IIntentReceiver接口,

//可以通过ReceiverDispatcher.getIIntentReceiver函数来获得,

                //获得后就会把它传给ActivityManagerService,以便接收广播。

final static class InnerReceiver extends IIntentReceiver.Stub {

final WeakReference<LoadedApk.ReceiverDispatcher> mDispatcher;

……

InnerReceiver(LoadedApk.ReceiverDispatcher rd, boolean strong) {

mDispatcher = new WeakReference<LoadedApk.ReceiverDispatcher>(rd);

……

}

……

}

 

……

 

final IIntentReceiver.Stub mIIntentReceiver;

final Handler mActivityThread;

……

ReceiverDispatcher(BroadcastReceiver receiver, Context context,

Handler activityThread, Instrumentation instrumentation,

boolean registered) {

……

 

mIIntentReceiver = new InnerReceiver(this, !registered);

mActivityThread = activityThread;

……

}

……

 

IIntentReceiver getIIntentReceiver() {

return mIIntentReceiver;

}

 

}

 

public class ActivityManagerService extends IActivityManager.Stub

        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {

……

 

public Intent registerReceiver(IApplicationThread caller, IIntentReceiver receiver, IntentFilter filter, String permission) {

synchronized(this) {


// 函数首先是获得调用registerReceiver函数的应用程序进程记录块

ProcessRecord callerApp = null;

if (caller != null) {

callerApp = getRecordForAppLocked(caller);

if (callerApp == null) {

……

}

}

 

List allSticky = null;

 

// Look for any matching sticky broadcasts…

Iterator actions = filter.actionsIterator();

if (actions != null) {

while (actions.hasNext()) {

String action = (String)actions.next();

allSticky = getStickiesLocked(action, filter, allSticky);

}

} else {

……

}

 

//广播接收器receiver保存一个ReceiverList列表中,这个列表的宿主进程是rl.app,这里就是MainActivity所在的进程了,
//在ActivityManagerService中,用一个进程记录块来表示这个应用程序进程,它里面有一个列表receivers,

//专门用来保存这个进程注册的广播接收器。接着,又把这个ReceiverList列表以receiver为Key值保存在

//ActivityManagerService的成员变量mRegisteredReceivers中,这些都是为了方便在收到广播时,快速找到对应的广播接收器的

ReceiverList rl

= (ReceiverList)mRegisteredReceivers.get(receiver.asBinder());

if (rl == null) {

rl = new ReceiverList(this, callerApp,

Binder.getCallingPid(),

Binder.getCallingUid(), receiver);

 

if (rl.app != null) {

rl.app.receivers.add(rl);

} else {

……

}

mRegisteredReceivers.put(receiver.asBinder(), rl);

}


  //创建一个BroadcastFilter来把广播接收器列表rl和filter关联起来,
//然后保存在ActivityManagerService中的成员变量mReceiverResolver中去


BroadcastFilter bf = new BroadcastFilter(filter, rl, permission);

rl.add(bf);

……

mReceiverResolver.addFilter(bf);

 

}

}

 

……

 

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/197491.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 【python量化】用python搭建一个股票舆情分析系统

    【python量化】用python搭建一个股票舆情分析系统写在前面下面的这篇文章将手把手教大家搭建一个简单的股票舆情分析系统,其中将先通过金融界网站爬取指定股票在一段时间的新闻,然后通过百度情感分析接口,用于评估指定股票的正面和反面新闻的占比,以…

  • c语言cstdio什么意思,<iostream>与<cstdio>有什么区别?

    c语言cstdio什么意思,<iostream>与<cstdio>有什么区别?该楼层疑似违规已被系统折叠隐藏此楼查看此楼列个提纲:1.cstdio是面向“文件”的,或者不强调文件和非文件流的区别,默认流就是可以关联外部文件,至于文件的外延是啥就不管,扔给宿主环境了。从std::FILE这个名字以及printf/scanf接口描述基于fprintf/fscanf上就可以看出来。iostream头只是包含了一坨东西,封装标准输入输出流,和文件流(在)不通用。2.cstdio不…

  • instsrv.exe srvany.exe用法「建议收藏」

    instsrv.exe srvany.exe用法「建议收藏」nstsrv.exe——来自Windows 2000 Resource Kits的一个小工具  微软官方对该小工具的说明:Installs and uninstalls executable services and assigns names to them.显而易见,这个小工具是用以安装和卸载可执行的服务和指派服务名给这些可执行的服务的。那么怎么去使用呢?这里我们设定要将F

  • Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure具体错误信息Causedby:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:CommunicationslinkfailureThelastpacketsuccessfullyreceivedfromtheserverwas1,548,635,756,564millisecondsago….

  • linux过滤端口抓包_linux抓包命令tcpdump[通俗易懂]

    linux过滤端口抓包_linux抓包命令tcpdump[通俗易懂]tcpdump是一个功能强大的命令行数据包分析器,它是通过监听服务器的网卡来获取数据包,所有通过网络访问的数据包都能获取到。它也提供了过滤器的功能,可以获取指定的网络、端口或协议的数据包程序员日常排查问题,最常用的是使用过滤器功能获取指定端口的数据包,用来分析服务器是否收到请求、请求数据是否完整。参数介绍tcpdump命令的参数很多,详见如下这里只介绍一些常用的参数​-ccountcount表示…

  • IntellIJ IDEA 配置 Maven和修改默认Repository

    IntellIJ IDEA 配置 Maven和修改默认Repository

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号