Multiple Windows in Android - SpiltScreen, PIP, and FreeForm

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 ?

Like
Reply

To view or add a comment, sign in

More articles by Weimin Ding

  • Face Recognization and Video Stream from RaspiBerry Pi

    Recently I am interested in making a smart camera with face recognization and video streaming feature, with several…

    1 Comment
  • Introduction of Amazon Alexa Skill

    Amazon Alexa skill has been existed for a while, however there is not a simple user guide to explain the procedure to…

  • Three principles of creating the product

    个人的体会,与大家共勉 创新产品三要素: 不要相信“功能越多,用户越满意”的鬼话,没有一个产品可以满足所有人。通过添加功能的方法满足多数人的方式来增加产品的价值的想法是错误的。因为每添加一个新功能的同时,就会给产品带来相应的坏处。…

    1 Comment
  • OAuth Workflow

    It might confuse many people when OAuth take place during authentication . Recently I have some time to study it and…

  • How to create Google Smart Home Action in 5 minutes

    Google Assistant is a platform to let user interactive with Google by voice or text. It has artificial intelligence as…

  • Deep Reinforcement Learning Example in OpenAI

    OpenAI Gym is a toolkit for developing and comparing reinforcement learning algorithms. This is the gym open-source…

  • AI, TensorFlow, Object Detection in Android -Part B

    Now we had the final training result available from the last topic, the first step is to verify it really work. Set up…

    2 Comments
  • Android BlueTooth-Step by Step

    Bluetooth becomes more and more popular in the handheld device. Almost every mobile phone has been functioned with…

  • Google IO 2018: Android Brief

    Google I/O is Google’s annual developer conference held in headquarters of Google. I/O stands for Input/Output but here…

Others also viewed

Explore content categories