page.title=Multi-Window Support page.metaDescription=New support in Android N for showing more than one app at a time. page.keywords="multi-window", "android N", "split screen", "free-form" @jd:body

In this document

  1. Overview
  2. Multi-Window Lifecycle
  3. Configuring Your App for Multi-Window Mode
  4. Running Your App in Multi-Window Mode
  5. Testing Your App's Multi-Window Support

See Also

  1. Multi-Window Playground sample app
  2. Five Tips for Preparing for Multi-Window in Android N

Android N adds support for displaying more than one app at the same time. On handheld devices, two apps can run side-by-side or one-above-the-other in split-screen mode. On TV devices, apps can use picture-in-picture mode to continue video playback while users are interacting with another app.

If you build your app with the N Preview SDK, you can configure how your app handles multi-window display. For example, you can specify your activity's minimum allowable dimensions. You can also disable multi-window display for your app, ensuring that the system only shows your app in full-screen mode.

Overview

Android N allows several apps to share the screen at once. For example, a user could split the screen, viewing a web page on the left side while composing an email on the right side. The user experience depends on the device:

Figure 1. Two apps running side-by-side in split-screen mode.

The user can switch into multi-window mode in the following ways:

Users can drag and drop data from one activity to another while the activities are sharing the screen. (Previously, users could only drag and drop data within a single activity.)

Multi-Window Lifecycle

Multi-window mode does not change the activity lifecycle.

In multi-window mode, only the activity the user has most recently interacted with is active at a given time. This activity is considered topmost. All other activities are in the paused state, even if they are visible. However, the system gives these paused-but-visible activities higher priority than activities that are not visible. If the user interacts with one of the paused activities, that activity is resumed, and the previously topmost activity is paused.

Note: In multi-window mode, an app can be in the paused state and still be visible to the user. An app might need to continue its activities even while paused. For example, a video-playing app that is in paused mode but is visible should continue showing its video. For this reason, we recommend that activities that play video not pause the video in their {@link android.app.Activity#onPause onPause()} handlers. Instead, they should pause video in {@link android.app.Activity#onStop onStop()}, and resume playback in {@link android.app.Activity#onStart onStart()}.

When the user puts an app into multi-window mode, the system notifies the activity of a configuration change, as specified in Handling Runtime Changes. This also happens when the user resizes the app, or puts the app back into full-screen mode. Essentially, this change has the same activity-lifecycle implications as when the system notifies the app that the device has switched from portrait to landscape mode, except that the device dimensions are changed instead of just being swapped. As discussed in Handling Runtime Changes, your activity can handle the configuration change itself, or it can allow the system to destroy the activity and recreate it with the new dimensions.

If the user is resizing a window and makes it larger in either dimension, the system resizes the activity to match the user action and issues runtime changes as needed. If the app lags behind in drawing in newly-exposed areas, the system temporarily fills those areas with the color specified by the {@link android.R.attr#windowBackground windowBackground} attribute or by the default windowBackgroundFallback style attribute.

Configuring Your App for Multi-Window Mode

If your app targets Android N, you can configure how and whether your app's activities support multi-window display. You can set attributes in your manifest to control both size and layout. A root activity's attribute settings apply to all activities within its task stack. For example, if the root activity has android:resizeableActivity set to true, then all activities in the task stack are resizeable.

Note: If you build a multi-orientation app with a version of the SDK lower than Android N, and the user uses the app in multi-window mode, the system forcibly resizes the app. The system presents a dialog box warning the user that the app may behave unexpectedly. The system does not resize fixed-orientation apps; if the user attempts to open a fixed-orientation app under multi-window mode, the app takes over the whole screen.

android:resizeableActivity

Set this attribute in your manifest's <activity> or <application> node to enable or disable multi-window display:

android:resizeableActivity=["true" | "false"]

If this attribute is set to true, the activity can be launched in split-screen and freeform modes. If the attribute is set to false, the activity does not support multi-window mode. If this value is false, and the user attempts to launch the activity in multi-window mode, the activity takes over the full screen.

If your app targets Android N, but you do not specify a value for this attribute, the attribute's value defaults to true.

android:supportsPictureInPicture

Set this attribute in your manifest's <activity> node to indicate whether the activity supports picture-in-picture display. This attribute is ignored if android:resizeableActivity is false.

android:supportsPictureInPicture=["true" | "false"]

Layout attributes

With Android N, the <layout> manifest element supports several attributes that affect how an activity behaves in multi-window mode:

android:defaultWidth
Default width of the activity when launched in freeform mode.
android:defaultHeight
Default height of the activity when launched in freeform mode.
android:gravity
Initial placement of the activity when launched in freeform mode. See the {@link android.view.Gravity} reference for suitable values.
android:minHeight, android:minWidth
Minimum height and minimum width for the activity in both split-screen and freeform modes. If the user moves the divider in split-screen mode to make an activity smaller than the specified minimum, the system crops the activity to the size the user requests.

For example, the following code shows how to specify an activity's default size and location, and its minimum size, when the activity is displayed in freeform mode:

<activity android:name=".MyActivity">
    <layout android:defaultHeight="500dp"
          android:defaultWidth="600dp"
          android:gravity="top|end"
          android:minHeight="450dp"
          android:minWidth="300dp" />
</activity>

Running Your App in Multi-Window Mode

Android N offers new functionality to support apps that can run in multi-window mode.

Disabled features in multi-window mode

Certain features are disabled or ignored when a device is in multi-window mode, because they don’t make sense for an activity which may be sharing the device screen with other activities or apps. Such features include:

Multi-window change notification and querying

The following new methods have been added to the {@link android.app.Activity} class to support multi-window display. For details on each method, see the N Preview SDK Reference.

Activity.isInMultiWindowMode()
Call to find out if the activity is in multi-window mode.
Activity.isInPictureInPictureMode()
Call to find out if the activity is in picture-in-picture mode.

Note: Picture-in-picture mode is a special case of multi-window mode. If myActivity.isInPictureInPictureMode() returns true, then myActivity.isInMultiWindowMode() also returns true.

Activity.onMultiWindowModeChanged()
The system calls this method whenever the activity goes into or out of multi-window mode. The system passes the method a value of true if the activity is entering multi-window mode, and false if the activity is leaving multi-window mode.
Activity.onPictureInPictureModeChanged()
The system calls this method whenever the activity goes into or out of picture-in-picture mode. The system passes the method a value of true if the activity is entering picture-in-picture mode, and false if the activity is leaving picture-in-picture mode.

There are also {@link android.app.Fragment} versions of each of these methods, for example Fragment.isInMultiWindowMode().

Entering picture-in-picture mode

To put an activity in picture-in-picture mode, call the new method Activity.enterPictureInPictureMode(). This method has no effect if the device does not support picture-in-picture mode. For more information, see the Picture-in-Picture documentation.

Launch New Activities in Multi-Window Mode

When you launch a new activity, you can hint to the system that the new activity should be displayed adjacent to the current one, if possible. To do this, use the flag Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT. Passing this flag requests the following behavior:

If a device is in freeform mode and you are launching a new activity, you can specify the new activity's dimensions and screen location by calling ActivityOptions.setLaunchBounds(). This method has no effect if the device is not in multi-window mode.

Note: If you launch an activity within a task stack, the activity replaces the activity on the screen, inheriting all of its multi-window properties. If you want to launch the new activity as a separate window in multi-window mode, you must launch it in a new task stack.

Supporting drag and drop

Users can drag and drop data from one activity to another while the two activities are sharing the screen. (Previously, users could only drag and drop data within a single activity.) For this reason, you may want to add drag and drop functionality to your app if your app does not currently support it.

The N Preview SDK extends the android.view package to support cross-app drag and drop. For details on the following classes and methods, see the N Preview SDK Reference.

android.view.DropPermissions
Token object responsible for specifying the permissions granted to the app that receives a drop.
View.startDragAndDrop()
New alias for {@link android.view.View#startDrag View.startDrag()}. To enable cross-activity drag and drop, pass the new flag View.DRAG_FLAG_GLOBAL. If you need to give URI permissions to the recipient activity, pass the new flags View.DRAG_FLAG_GLOBAL_URI_READ or View.DRAG_FLAG_GLOBAL_URI_WRITE, as appropriate.
View.cancelDragAndDrop()
Cancels a drag operation currently in progress. Can only be called by the app that originated the drag operation.
View.updateDragShadow()
Replaces the drag shadow for a drag operation currently in progress. Can only be called by the app that originated the drag operation.
Activity.requestDragAndDropPermissions()
Requests the permissions for the content URIs passed with the {@link android.content.ClipData} contained in a {@link android.view.DragEvent}.

Testing Your App's Multi-Window Support

Whether or not you update your app for Android N, you should verify how it behaves in multi-window mode in case a user tries to launch it in multiwindow mode on a device running Android N.

Configuring a Test Device

If you install Android N on a device, split-screen mode is automatically supported.

If your app was not built with the N Preview SDK

If you did not build your app with the N Preview SDK and the user attempts to use the app in multi-window mode, the system forcibly resizes the app unless the app declares a fixed orientation.

If your app does not declare a fixed orientation, you should launch your app on a device running Android N and attempt to put the app in split-screen mode. Verify that the user experience is acceptable when the app is forcibly resized.

If the app declares a fixed orientation, you should attempt to put the app in multi-window mode. Verify that when you do so, the app remains in full-screen mode.

If you support multi-window mode

If you built your app with the N Preview SDK and have not disabled multi-window support, verify the following behavior under both split-screen and freeform modes.

Testing checklist

To verify your app's performance in multi-window mode, try the following operations. You should try these operations in both split-screen and multi-window mode, except where otherwise noted.

If you have disabled multi-window support

If you disabled multi-window support by setting android:resizableActivity="false", you should launch your app on a device running Android N and attempt to put the app in freeform and split-screen modes. Verify that when you do so, the app remains in full-screen mode.