Flujo de trabajo de la vista 1

El flujo de trabajo de Ver se refiere a medir, diseñar y dibujar. Entre ellos, la medida se usa para medir el ancho y el alto de View. El diseño se usa para determinar la posición de la vista y el dibujo se usa para dibujar la vista.

Ver entrada de flujo de trabajo

Anteriormente hablamos sobre la composición de Activity. Luego se trata de la creación de DecorView y los recursos que carga. En este momento, el contenido de DecorView no se puede mostrar porque no se cargó en la ventana. A continuación, nos enfocamos en aprender cómo se carga DecorView en Window.

1DecorView se carga en la ventana

Cuando DrcorView se crea y se carga en la ventana, debemos comprender el proceso de creación de la actividad.

Cuando llamamos a startActivity de la actividad, finalmente llamamos a handleLaunchActivity de ActivityThread.Hay una oración de este tipo en el código:

Activity a = performLaunchActivity(r,customIntent)

Aquí se llama al método performLaunchActivity para crear la actividad, y se llama al método onCreate de la actividad en este método para completar la creación de DecorView.

En el siguiente código, también hay una llamada al método handleResumeActivity,

@Override
    public void handleResumeActivity(ActivityClientRecord r, boolean finalStateRequest,
            boolean isForward, String reason) {
        // If we are getting ready to gc after going to the background, well
        // we are back active so skip it.
        unscheduleGcIdler();
        mSomeActivitiesChanged = true;

        // TODO Push resumeArgs into the activity for consideration
        // skip below steps for double-resume and r.mFinish = true case.
        if (!performResumeActivity(r, finalStateRequest, reason)) {
            return;
        }
        if (mActivitiesToBeDestroyed.containsKey(r.token)) {
            // Although the activity is resumed, it is going to be destroyed. So the following
            // UI operations are unnecessary and also prevents exception because its token may
            // be gone that window manager cannot recognize it. All necessary cleanup actions
            // performed below will be done while handling destruction.
            return;
        }

        final Activity a = r.activity;

        if (localLOGV) {
            Slog.v(TAG, "Resume " + r + " started activity: " + a.mStartedActivity
                    + ", hideForNow: " + r.hideForNow + ", finished: " + a.mFinished);
        }

        final int forwardBit = isForward
                ? WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION : 0;

        // If the window hasn't yet been added to the window manager,
        // and this guy didn't finish itself or start another activity,
        // then go ahead and add the window.
        boolean willBeVisible = !a.mStartedActivity;
        if (!willBeVisible) {
            willBeVisible = ActivityClient.getInstance().willActivityBeVisible(
                    a.getActivityToken());
        }
        if (r.window == null && !a.mFinished && willBeVisible) {
            r.window = r.activity.getWindow();
            View decor = r.window.getDecorView();
            decor.setVisibility(View.INVISIBLE);
            ViewManager wm = a.getWindowManager();
            WindowManager.LayoutParams l = r.window.getAttributes();
            a.mDecor = decor;
            l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
            l.softInputMode |= forwardBit;
            if (r.mPreserveWindow) {
                a.mWindowAdded = true;
                r.mPreserveWindow = false;
                // Normally the ViewRoot sets up callbacks with the Activity
                // in addView->ViewRootImpl#setView. If we are instead reusing
                // the decor view we have to notify the view root that the
                // callbacks may have changed.
                ViewRootImpl impl = decor.getViewRootImpl();
                if (impl != null) {
                    impl.notifyChildRebuilt();
                }
            }
            if (a.mVisibleFromClient) {
                if (!a.mWindowAdded) {
                    a.mWindowAdded = true;
                    wm.addView(decor, l);
                } else {
   
   

En este método, se llamará a performeResumeActivity, y en performResumeActivity, se llamará al método onResume de Activity.

Mira el siguiente código:

Ver decoración = r.window.getDecorView();

Aquí, se obtiene DecorView y luego se obtiene WindowManager. WindowManager es una interfaz y hereda la interfaz ViewManager. Llame al método wm.addView al final. La clase de implementación de WindowManager es WindowManagerImpl, por lo que en realidad se llama al método addView de WindowManagerImpl. Hay tal código en él:

mGloal.addView(vista,parámetros,mDisplay,mParentWindow);

Se puede ver que en el método addView de WindowManagerImpl, se llama al método addView de WindowManagerGlobal.En este método, hay una oración de este tipo:

root = new ViewRootImpl(view.getContext(),display);

Este código crea una instancia de ViewRootImpl, y luego hay un código de este tipo a continuación:

root.setView(ver,wparams,panelParentView);

Aquí llame al método setView de ViewRootImpl para pasar DeccorView como parámetro. Esto carga DecorView en la ventana. Por supuesto, no se mostrará nada en la interfaz en este momento, porque el flujo de trabajo de Vista aún no se ha ejecutado, y la vista debe dibujarse mediante medición, diseño y dibujo.

Supongo que te gusta

Origin blog.csdn.net/howlaa/article/details/128555575
Recomendado
Clasificación