Android Toast显示流程

@MainActivity.java
Toast.makeText(MainActivity.this, "xww make toast", Toast.LENGTH_SHORT)
@frameworks/base/core/java/android/widget/Toast.java
    makeText(context, null, text, duration);
        Toast result = new Toast(context, looper);
            mContext = context;  // Toast的context
            mTN = new TN(context, context.getPackageName(), mToken, mCallbacks, looper);
@frameworks/base/core/java/android/widget/ToastPresenter.java
                mPresenter = new ToastPresenter(context, accessibilityManager, getService(), packageName);
                    mContext = context;  //ToastPresenter的context
@frameworks/base/core/java/android/app/ContextImpl.java
                    mWindowManager = context.getSystemService(WindowManager.class);
                        SystemServiceRegistry.getSystemServiceName(serviceClass);
                            final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass);
                            return serviceName;
        View v = ToastPresenter.getTextToastView(context, text);
            View view = LayoutInflater.from(context).inflate(TEXT_TOAST_LAYOUT, null);
            TextView textView = view.findViewById(com.android.internal.R.id.message);
            textView.setText(text);
            return view;
       result.mNextView = v; // Toast的context
.show())
    INotificationManager service = getService();
        sService = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    TN tn = mTN;
    tn.mNextView = mNextView; // 设置TN的mNextView
    final int displayId = mContext.getDisplayId();
@frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
    service.enqueueToast(pkg, mToken, tn, mDuration, displayId);
@frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
        mWindowManagerInternal.addWindowToken(windowToken, TYPE_TOAST, displayId,null
        record = getToastRecord(callingUid, callingPid, pkg, isSystemToast, token, text, callback, duration, windowToken, displayId, textCallback);  // callback等于TN
        return new CustomToastRecord(this, uid, pid, packageName,isSystemToast, token, callback, duration, windowToken, displayId);
            final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */);
            new WindowToken.Builder(this, binder, type).setDisplayContent(dc) .setPersistOnEmpty(true).setOwnerCanManageAppTokens(true).setOptions(options).build();
        mToastQueue.add(record);
        showNextToastLocked(false);
            ToastRecord record = mToastQueue.get(0);
            tryShowToast(record, rateLimitingEnabled, isWithinQuota, isPackageInForeground))
@frameworks/base/services/core/java/com/android/server/notification/toast/CustomToastRecord.java
                record.show();
@frameworks/base/core/java/android/widget/Toast.java
                    callback.show(windowToken);  //TN.show
                        mHandler.obtainMessage(SHOW, windowToken).sendToTarget();
                            void handleMessage(Message msg) {
                                case SHOW: {
                                    handleShow(token);
                                        mView = mNextView; //获取TN的mNextView
                                        mPresenter.show(mView, mToken, windowToken, mDuration, mGravity, mX, mY, mHorizontalMargin, mVerticalMargin, new CallbackBinder(getCallbacks(), mHandler));
                                            addToastView();
@frameworks/base/core/java/android/view/WindowManagerImpl.java
                                                mWindowManager.addView(mView, mParams);
@frameworks/base/core/java/android/view/WindowManagerGlobal.java
                                                    mGlobal.addView(view, params, mContext.getDisplayNoVerify(), mParentWindow, mContext.getUserId());    //WindowManagerImpl的mContext

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛文旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值