1. Android N introduces multi-window mode which allows users to use multiple apps simultaneously by displaying them in split-screen or picture-in-picture modes.
2. Developers can configure their apps to support multi-window mode through settings like android:resizeableActivity and by handling configuration changes and lifecycle methods appropriately when an app is in a paused state but still visible.
3. Best practices for multi-window include designing first for the smallest screen size, handling all orientations, and ensuring activities work properly when launched by other apps in multi-window mode.
3. What is Multi-Window
Android N adds support for displaying more than one app at the same time.
● Split-Screen Mode (分割畫面模式)
● Picture-in-picture Mode (子母畫面模式)
● Freeform mode (自由形式模式)
4. Switch into multi-window mode
● 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.
6. Picture-in-picture(子母畫面) Mode
In Android N, Android TV users can now watch a video in a pinned window in a
corner of the screen when navigating within apps.
Picture-in-picture (PIP) mode lets apps run a video activity in the pinned
window while another activity continues in the background. The PIP window
lets users multitask while using your app, which helps users be more
productive.
7. Picture-in-picture Mode
The PIP window is 240 x 135 dp and is shown at the top-
most layer in one of the four corners of the screen,
chosen by the system.
The user can bring up a PIP menu that lets them toggle
the PIP window to fullscreen, or close the PIP window, by
holding down the Home button on the remote.
11. 1. adb shell
2. su
3. setenforce 0
4. settings put global enable_freeform_support 1
5. cd /data/local/tmp
6. mkdir permissions
7. cd permissions
8. cp -a /system/etc/permissions/* ./
9. sed -e “s/live_wallpaper/freeform_window_management/” android.software.live_wallpaper.xml
>freeform.xml
10. mount --bind . /system/etc/permissions
11. stop
12. start
How to enable freeform on emulator
Ref : http://lifehacker.com/heres-
what-freeform-windows-in-
android-n-look-like-and-
1766353465
12. Multi-Window Lifecycle
Multi-window mode does not change the activity lifecycle.
Only one resume activity in the system (the currently focused activity); all other
visible activities are in the pause state, even they are visible.
13.
14. Multi-Window Lifecycle handle
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 onPause() handlers. Instead, they should pause video in onStop(),
and resume playback in onStart().
15. Configuration Changes
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 -
screenSize, smallestScreenSize, screenLayout, orientation.
@Override
public void onConfigurationChanged(Configuration newConfig) {
...
}
<activity
android:name=".MyActivity"
android:configChanges="screenSize|smallestScreenSize |screenLayout|orientation"
...
/>
16. Configuring App for Multi-Window Mode
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.
17. Layout styleable
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
● android:minimalHeight, android:minimalWidth
19. Launch New Activities in Multi-Window Mode
Split-Screen Mode Only
android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
Intent intent = new Intent(this, AdjacentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.
FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
20. Start activity at specific location & size
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.
22. Drag and drop
Users can drag and drop data from one activity to
another while the two activities are sharing the
screen.
1. Detect the gesture
2. Prepare the data
3. Start the drag
4. Monitor the progress
5. Handle the drop
23. Drag and drop
android.view.DropPermissions android.view.DragAndDropPermissions
Activity.requestDropPermissions() Activity.requestDragAndDropPermissions()
View.startDragAndDrop()
View.DRAG_FLAG_GLOBAL
View.DRAG_FLAG_GLOBAL_URI_READ
View.DRAG_FLAG_GLOBAL_URI_WRITE
View.cancelDragAndDrop()
View.updateDragShadow()
24. Tablet and phone layouts in split-screen
Apps may use the same or different layouts for mobile and tablet:
● Apps with similar layouts for mobile and tablet may switch between the tablet and
mobile UIs when the app is resized, as the transition will not be jarring.
● Apps with completely different layouts for mobile and tablet should avoid using
the mobile UI on tablet in split-screen mode. Instead, the existing tablet UI should be
adapted to fit the smaller size to ensure that users have a consistent experience on
both devices.
25.
26.
27. Design for condensed sizes first
● Design for the smallest size first
● Start with a 220dp wide or tall layout, condensing and removing non-
essential elements.
28. 5 tips for preparing for Multi-Window in
Android N
1. Best to keep your UI stuff with the Activity Context.
2. Handle configuration changes correctly
3. Handle all orientations
a. For apps not targeting Android N, adding android:screenOrientation means you will not
support multi-window at all
4. Build a responsive UI for all screen sizes
5. Activities started by other apps must always support multi-window
Ref: https://medium.com/google-developers/5-tips-for-preparing-for-multi-window-in-android-n-
7bed803dda64