Anyone who has worked in multi-window mode on an Android device can confirm that this is very convenient in certain situations. A simple example: reading an e-book with the same electronic dictionary. Especially - on a smartphone or tablet with a fairly large screen.
If the user has to choose between two applications that are similar in almost everything, but differing in support for simultaneous work with several windows, it is not surprising that he will choose what this support provides.

From the article you will learn about multi-window mode in Android, and how to use this feature when building your own applications.
Overview
Simultaneous work with multiple windows in Android is an interesting feature that can distinguish your application from many others and give it an additional competitive advantage. Many OEM and ODM manufacturers, such as Samsung, Ramos and Huawei, are refining the basic Android system. In particular, they are implementing support for multi-window mode. They do this in order to increase the attractiveness of their smartphones and tablets, to distinguish them from the bulk of devices that do not support this function.
')
Multiple Mode ScenariosPreliminary Information
In June 2012,
Cornerstone was introduced, the first open source platform for multitasking on Android. In August 2012, Samsung released the first device that supports multi-window operation. Starting from 2013 and up to now, you can observe the explosive growth of solutions to support simultaneous work with several windows in Android.
In May 2015, the Android M Developer Preview came out (today, in July, Preview 2 is already available). The official release of Android M (6.0) is expected in the fall of 2015. In addition to other innovations, Android M Preview 2 is notable for the fact that it supports multi-window mode.
The development of solutions to support multitasking in AndroidThere are two approaches to working with multiple windows: the use of floating (floating) and fixed (docked) windows. Among the main features of work in multi-window modes are the opening and closing of windows (open / close), changing their size (resize) and relative positioning (swap). Opening or closing the window, we, respectively, turn on or off the multi-window mode. The resize feature provides for customizing window sizes. Changing the location of windows is an action that allows you to swap them.
Multiple window modesIn 2013, a number of solutions designed to work with multiple windows appeared on the market. They were developed by OEM and ODM, independent software vendors, and the open source community. In the table below you can find a comparison of various technologies of organizing multi-window work in the Android environment.
Product | Cornerstone | Standout | Xposed | Tieto |
Description
| Framework for multitasking in the Android OS
| An open source library that can be used to create applications with floating windows.
| Multi-window application that supports docked windows
| The project aims to create a working environment that resembles desktop work.
|
Support for opening, closing windows, resizing, expanding to full screen
| Yes
| Yes
| Yes
| Yes
|
Window style
| Fixed
| Floating
| Fixed
| Fixed and floating
|
Code modification
| At the level of the Android platform
| At the application level
| At the level of the Android platform
| At the level of the Android platform
|
Application support
| All applications are supported, however, the dynamic configuration of SurfaceView is not available.
| Some helper applications. For example - a calculator.
| Compatibility and stability of the solution needs to be improved.
| Supports all applications.
|
Android version
| Android 4.1. - Android 4.4.
| Android 4.1. - Android 4.4.
| Android 4.4.
| Android 4.4
|
Official site
| Cry
| Cry
| Cry
| Cry
|
Software architecture
The code of the Android platform can be modified in order to equip it with support for additional features. The architecture of the Android OS consists of several levels.
In the case of Android 4.2 and Android 4.3., The shell (launcher) and other applications are placed on the same stack at the start, called the “main stack”. As you know, multi-window mode requires more stacks to accommodate several windows. As a result, you need to modify the system class ActivityManagerService, adding to it an interface for creating a stack and managing it. To modify the class platform WIndowManagerService, which allows you to manage the graphical representations of applications, you need to change the InputManager. This is needed so that it can redirect touch events to the appropriate windows.
With the release of Android 4.4 and Android 5.0, the approach to managing the stack has changed significantly. The shell and other applications can run in different stacks. The system has added support for multiple stacks and the ability to manage them. The figure below shows the differences in working with the stack in different versions of Android.
Comparison of work with the stack in Android 4.3 and Android 4.4Now focus on Android 5 (Lollipop). The Android OS uses callback mechanisms to perform the interface functions of the Activity. However, the control function is implemented at the platform level. Therefore, we now consider two important classes: ActivityManagerService and WindowManagerService.
Lollipop platform software structureManage Activity in Lollipop
Since the ability to work in a multi-window mode depends on the stack, below is shown how you can create a stack and how you can start an Activity in this stack. In Lollipop, the following functions have been added to the IactivityManager.java interface:
New interface features IactivityManager.java | Description |
public void moveTaskToStack (int taskId, int stackId, boolean toTop) | Move a task to another stack |
public void resizeStack (int stackBoxId, Rect bounds)
| Change stack size
|
public void setFocusedStack (int stackId)
| Set focus on selected task
|
Public Boolean isInHomeStack (int taskId)
| Find out if the task is in HomeStack
|
After starting, the SystemServer process calls the activity management services (activity manager services) and windows management services. In order to observe this process, we can add the Runtime exception exception (RuntimeException) command to the appropriate places.
The process of creating a stack in LollipopNow let's see how to start the Activity in the stack:
Running an Activity on the StackThe following commands have been added to Lollipop to the ADB utility (Android Debug Bridge, Android debugging bridge):
ADB Team
| Function
| Description
|
Adb shell stack stack
| Launches a new Activity on <DISPLAY_ID> using an Intent
| In Kitkat 4.4, ADB commands contain: adb shell am stack create In Lollipop 5.0: adb shell stack
|
Adb shell stack stack movetask
| Move <TASK_ID> from the current stack up or down the stack <STACK_ID>
| Usage: adb shell am stack movetask task_id stackid true / false Note: it works in Kitkat, but not in Lollipop
|
Adb shell stack stack resize
| Resizes the stack size <STACK_ID> and its position to <LEFT, TOP, RIGHT, BOTTOM>
| Usage: adb shell stack stack resize task_id weight
|
Office windows in Lollipop
WindowManagerService is the central part of the window management system. Its functionality includes dispatching input events, managing the location of objects on the screen, and surfaces on which graphical elements are displayed.

The role of WindowsManagerService in the Android graphical architectureMulti-Mode Problems
When working in multi-window mode, resizing windows is available. There are examples when the size of the window that displays the game animation cannot be changed. The main reason for this is that the Android SurfaceFlinger subsystem cannot dynamically change the size of the displayed image.
Games using SurfaceFlinger cannot dynamically resize a windowAnother problem is that some applications in multi-window mode are displayed incorrectly. In the figure below you can see that the calculator is not displayed correctly in multi-window mode. It's all about the layout of the application, which is not designed for such conditions of use.
Calculator with a layout that is not designed to work in multi-window modeMulti-window support in Android M
Android M Developer Preview 2 can be run on Nexus 5, 6, 9 and Nexus Player. If you don’t have such a device, or you don’t want to install an OS that is in the Preview status, you can get acquainted with Android M using an emulator in Android Studio. In particular, we are now interested in standard tools for working in a multi-window mode.
In order to see this mode in action, it is enough to create a new virtual device using the AVD Manager tool, while selecting one of those available with the Level API MNC as the system image. In our case, it was the x86_64 image. Next, you need to start the emulator, go to the settings section For the developer and enable the Multi-window mode option there. If this option cannot be found, take a look at this
manual.Now the fun part. For starters, you can run several applications, everything will be as usual. But if you click on the button to call the list of recently opened applications, a new icon will appear in the window thumbnails headers. By default, this is a frame indicating that the application is running in full screen mode. If you click on this icon, the window layout selection menu appears.
The menu for choosing the layout of windows in multi-window modeThen everything is quite clear. Select the desired layout and enjoy the multi-window mode:
Multi-mode in Android MIt is still unknown whether work with several windows will be available in the official release of Android M. However, for example, the system calculator in this mode feels good. As a result, we have serious reasons to believe that the day is not far off when adapting applications for a multi-window mode from competitive advantage will become a vital necessity.
If you want to equip your applications designed for earlier versions of Android, support for multiple windows, it's time to turn to third-party solutions, which were discussed above. For example, to Cornerstone.
Example: Cornerstone
The company Onskreen created Cornerstone - the first framework that allows you to work with multiple windows on Android. It is designed for devices with large screens and tablets. Source code can be downloaded on
Github . It supports work with Android versions 4.1 and 4.2. For later versions of this OS, Cornerstone has not yet been released. However, you can analyze the source code for Android 4.2 in order to learn the technical details of the system.
Cornerstone modifications in Android Jelly BeanResults
Many mobile devices running Android OS use Intel® processors. How can developers improve the user experience of working with their applications? How to make applications more competitive? These questions lead us to continually improving products on devices with Intel Architecture (IA). Multi-window support is a good example of a useful feature that provides applications with competitive advantages. This convenient, multi-window mode allows the user to perform several tasks simultaneously. For example - to watch videos and write to friends about what they are watching. For example - to play the game and read its reviews. Today, work in multi-mode support multiple devices. For example, these are the Ramos i12, Teclast x98 and Cube i7 tablets, which run under Remix OS.
Multi-window mode on IA devicesFor home reading
»
Android 6.0 Muffin Concept Video Shows Multi-Windows, Quick Reply FeatsThanks for attention!