android Q /R/S/T onTopResumedActivityChanged method parsing

Question background:

In the high version of Android Q, when you often look at the Activity life cycle through the events log, you often see the following prints:

06-27 12:02:07.091  4812  4812 I wm_on_top_resumed_gained_called: [227500858,com.android.launcher3.uioverrides.QuickstepLauncher,topStateChangedWhenResumed]
06-27 12:02:07.092  4812  4812 I wm_on_top_resumed_lost_called: [227500858,com.android.launcher3.uioverrides.QuickstepLauncher,topStateChangedWhenResumed]

That is, there are wm_on_top_resumed_gained_called and wm_on_top_resumed_lost_called related prints. When I saw it for the first time, I was still wondering what this thing is for? How does resumed increase and lose?
insert image description here

Answers to questions:

1. Search for
wm_on_top_resumed_gained_called according to the clues of the events log. Generally, this kind of tag is generally shown in the code as follows: WmOnToResumeGainedCalled
insert image description hereHere you can find the relevant code:

final void performTopResumedActivityChanged(boolean isTopResumedActivity, String reason) {
    
    
    onTopResumedActivityChanged(isTopResumedActivity);

    if (isTopResumedActivity) {
    
    
        EventLogTags.writeWmOnTopResumedGainedCalled(mIdent, getComponentName().getClassName(),
                reason);
    } else {
    
    
        EventLogTags.writeWmOnTopResumedLostCalled(mIdent, getComponentName().getClassName(),
                reason);
    }
}

Printed after onTopResumedActivityChanged is executed.

Let's focus on onTopResumedActivityChanged

 /**
     * Called when activity gets or loses the top resumed position in the system.
     *
     * <p>Starting with {@link android.os.Build.VERSION_CODES#Q} multiple activities can be resumed
     * at the same time in multi-window and multi-display modes. This callback should be used
     * instead of {@link #onResume()} as an indication that the activity can try to open
     * exclusive-access devices like camera.</p>
     *
     * <p>It will always be delivered after the activity was resumed and before it is paused. In
     * some cases it might be skipped and activity can go straight from {@link #onResume()} to
     * {@link #onPause()} without receiving the top resumed state.</p>
     *
     * @param isTopResumedActivity {@code true} if it's the topmost resumed activity in the system,
     *                             {@code false} otherwise. A call with this as {@code true} will
     *                             always be followed by another one with {@code false}.
     *
     * @see #onResume()
     * @see #onPause()
     * @see #onWindowFocusChanged(boolean)
     */
    public void onTopResumedActivityChanged(boolean isTopResumedActivity) {
    
    
    }

The following points can be translated from the comments:
1. After android Q, activities under multiple composite windows can be resumed at the same time, that is, multiple activities are in the Resumed state, so only onResume can no longer simply satisfy
2. This callback The parameter isTopResumedActivity
is true, which means that the current activity is the latest resumed activity, and it also means that it is the top resumed activity.
False means that it is no longer the top resumed activity.

3. The app can conveniently control some things such as camera acquisition through this callback. It needs to give up the relevant resources to the resumed activity at the top. Summary: Simply put,
multiple
activities in the new version of Android can be resumed at the same time, such as split screen and free window , multi-screen display, etc., but generally the activity that is resumed at the top finally gets the user's focus. With this callback, it is convenient for the activity to control some of its own resource release and acquisition.

For more questions and answers related to actual combat, please pay attention to the public account "Qianlima Learning Framework"

おすすめ

転載: blog.csdn.net/learnframework/article/details/131413808