Starting with Android 7.0, Google has launched a new feature called "Multi-Window Mode", which is what we often call "split screen mode". So, what's the use of this function? As developers, what can we do?
Android 7.0 adds support for displaying multiple apps at the same time. On handheld devices, the two APPs can run side by side in split-screen mode.
Well, that's probably it:
Adaptation of split-screen mode
How can we make our APP support split-screen mode?
If the targetSDKVersion of the project is greater than or equal to 24, you can control whether the entire APP or an activity supports split screen by setting android:resizeableActivity=["true" | "false"] in the Application or Activity node of the file. The default value of this property is true, that is, if this property is not set, the default is that it can be split-screen on devices that support split-screen.
If the project's targetSDKVersion is less than 24, then when running on a device that supports split-screen, the split-screen can be split-screen by default. At this time, if you need to prohibit split screen, you need to set the android:screenOrientation property on the Application or Activity node of the file to control the screen direction of the entire APP or an Activity, thereby controlling the entire APP or an Activity to prohibit split screen.
Split screen mode monitoring
Can I listen to the APP in the code and enter split screen mode? The answer is yes. Since the APP will execute the onMultiWindowModeChanged method when the split-screen mode changes, we can rewrite this method in the Activity to realize split-screen monitoring.
@Override public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { (isInMultiWindowMode); // Determine whether it is currently split-screen mode if (isInMultiWindowMode) { // has entered split screen mode } else { // Split screen mode has not entered } }
Life cycle in split-screen mode
It should be noted that the life cycle of the Activity when entering and exiting split screen mode.
When entering split screen mode, the life cycle of the Activity:
onPause()->onStop()->onMultiWindowModeChanged()->onDestroy()->onCreate()->onStart()->onResume()->onPause()
When exiting split screen mode, the life cycle of the Activity:
onStop()->onDestroy()->onCreate()->onStart()->onResume()->onPause()->onMultiWindowModeChanged()->onResume()
It can be seen that when entering split screen mode, Activity is executed firstonMultiWindowModeChanged
Method, rebuild yourself. When exiting split screen mode, Activity first rebuilds itself and then executesonMultiWindowModeChanged
method.
This will have a problem. When our APP enters split screen mode,onMultiWindowModeChanged
If there are operations on UI, etc. in the method, the automatic reconstruction will be of no effect. To prevent this, it is necessary to
The Activity node sets the following properties:
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
With this property set, the Activity will not be automatically rebuilt when entering split screen mode.
Judgment of split-screen mode
We can use the isInMultiWindowMode() method of Activity to get whether it is currently entering split screen mode. This method returns true to indicate that it has entered split screen mode, and return false to indicate that it has not entered split screen mode.
if (isInMultiWindowMode()) { // has entered split screen mode } else { // Split screen mode has not entered }
Open Activity in split screen mode
If the Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT and Intent.FLAG_ACTIVITY_NEW_TASK flags are set for Intent when the APP opens Activity in split-screen mode, the newly opened Activity will be displayed on the other side of the current APP. For example, the following code:
Intent intent = new Intent(this, ); (Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT|Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
As shown in the figure, the original Activity is displayed on the upper half of the screen after split screen, and the newly opened Activity is displayed on the lower half of the original Activity (the lower half of the screen).
This is the article about the implementation of Android 7.0 multi-window split screen mode. For more related contents of Android 7.0 multi-window split screen, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!