Multiple Windows in Android - SpiltScreen, PIP, and FreeForm
From Android Nouget, Google adds support for displaying more than one app at the same time. The first feature they add is
Split-Screen Mode
Split-screen mode enables two apps can run side-by-side or one-above-the-other. Such as this
Enable/Disable feature
The application could enable/disable split-screen support in AndroidManifest.xml. Target API higher than 24 and put below configuration in AndroidManifest.xml
android:resizeableActivity="true|false"
Enter Split-Screen by User
The user can switch into multi-window mode in the following ways:
If the user opens the Overview screen and performs a long press
on an activity title, they can drag that activity to a highlighted
portion of the screen to put the activity in multi-window mode.
If the user performs a long press on the Overview button,
the device puts the current activity in multi-window mode
and opens the Overview screen to let the user choose another
activity to share the screen.
In another word, Split-mode is passive mode regards to the application because the application could not enter this mode proactively. It will be triggered by user interaction and managed by the system. Even there is some flag could be set when starting new Activity, it does not convert current activity into the multi-window mode.
Exit Split-Screen by User
If user pull down or pull up the divider between 2 activitys, it will
only display one activity in whoel screen.
Enter Split-Screen by Application
As we mentioned, the application has no option to enter split-screen proactivity
Exit Split-Screen by Application
As we mentioned, the application has no option to exit split-screen proactivity
Picture-in-Picture Mode
Starting with Android 8.0, apps can put themselves in picture-in-picture mode, allowing them to continue showing content while the user browses or interacts with other apps.
Enable/Disable feature
The application could enable/disable picture-in-picture support in AndroidManifest.xml. Target API higher than 26 and put below configuration in AndroidManifest.xml
android:supportsPictureInPicture ="true|false"
Enter Picture-in-Picture by User
Basically, the user has no way to force application into pip mode. Some applications such as Google Chrome will display in pip mode if the user clicks the home button, but it is designed for each application and not every app follow the same rules.
Exit Picture-in-Picture by User
The system will restore the activity if the user double-clicks the pip screen. App did not need any extra work but be careful the handling of the activity restart
Enter Picture-in-Picture by Application
Please set minsdk is 26 and above and put an activity in picture-in-picture mode, call below inside your code. This method has no effect if the device does not support picture-in-picture mode
Activity.enterPictureInPictureMode(PictureInPictureParams params
)
PictureInPIctureParams define how activity displayed on the screen include its width, height..etc.
One sample data would be looks like this
PictureInPictureParams.Builder mPictureInPictureParamsBuilder =
new PictureInPictureParams.Builder();
// set size
int width = 400; // pixel size
int height = 300; // pixel size
Rational aspectRatio = new Rational(400, 300);
//set actions
final ArrayList<RemoteAction> actions = new ArrayList<>();
actions.add(
new RemoteAction(
Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
getString(R.string.info),
getString(R.string.info_description),
PendingIntent.getActivity(
MainActivity.this,
REQUEST_INFO,
new Intent(
Intent.ACTION_VIEW,
Uri.parse(getString(R.string.info_uri))),
0)));
//build
mPictureInPictureParamsBuilder
.setAspectRatio(aspectRatio)
.setActions(actions)
.build();
//change to pip mode
enterPictureInPictureMode(mPictureInPictureParamsBuilder.build());
If the activity does not have this function, please check if your dependency in the build.gradle if it is version beyond 27.0.0
Exit Picture-in-Picture by Application
Apparently, there is no straightforward method the exit pip mode, the application could stop itself and restart activity in the normal way to achieve this.
Free Form Mode
Freeform allows users to dynamically resize the activity panes and have more than two apps visible on their screen.
Basically, Free-Form feature needs to be enabled by the manufacturer while they compile and rebuild the Android system. If the native Android system resides on your device, this feature is available right now for any Android 7.0 device.
Enable/Disable feature
There is no special flag to turn on or off this feature. If resized activity feature is true, then it should be turn on.
android:resizeableActivity="true|false"
In some old device, it might need to enable setting through adb
adb shell settings put global enable_freeform_support 1
Enter Free-Form by User
Basically, the user has no way to force application into free-form mode unless the application is designed to do this way
Exit Free-Form by User
The user could click the monitor icon at the title bar of activity to restore activity display in full screen
Enter Free-Form by Application
Please set minsdk is 26 and above and launch the activity with AcivityOptions.
//Define the bounds in which the Activity will be launched into.
Rect bounds = new Rect(0,0,300,300);
// Set the bounds as an activity option.
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchBounds(bounds);
// Start the LaunchBoundsActivity with the specified options
Intent intent = new Intent(this, FreeFormActivity.class);
intent.addFlags(
Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent, options.toBundle());
Exit Free-Form by Application
Apparently, there is no straightforward method the exit pip mode, the application could stop itself and restart activity in the normal way to achieve this.
Thanks for your reading, below is sample code for my article. Let me know if you have any comments
https://github.com/alading/android_multiple_window_example.git
Thanks for article. Is it possible in split-screen mode split more than two screen ? Can I add more than two apps with splitter ?