![](http://habrastorage.org/getpro/habr/avatars/5f9/7d8/b41/5f97d8b41f4dd4e88098693f9213f853.png)
Multi-window mode: an additional competitive advantage for Android applications
- Transfer
Everyone who worked in multi-window mode on an Android device can confirm that in certain situations it is very convenient. A simple example: reading an e-book with an 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 differ in support for simultaneous work with multiple windows, it is not surprising that he will choose what provides such support. From the article you will learn about multi-window mode in Android, and how to use this feature when building your own applications.
![](https://habrastorage.org/files/660/d52/714/660d52714cd141b8b68ac06f30bb0a1f.jpg)
Simultaneous work with multiple windows in Android is an interesting feature that can distinguish your application from many others, give it an additional competitive advantage. Many OEMs and ODMs, such as Samsung, Ramos, and Huawei, are modifying the base Android system. In particular, they are introducing multi-window support. 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 such a function.
![](https://habrastorage.org/getpro/habr/post_images/b88/a01/c31/b88a01c3172f1f0d5cf6d46a6225dc6a.png)
Scenarios for using multi-window mode
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. From 2013 to the present, you can observe the explosive growth of solutions to support the simultaneous work with multiple windows in Android.
In May 2015, Android M Developer Preview was released (today, in July, Preview 2 is already available). The official release of Android M (6.0) is expected in the fall of 2015. Among other innovations, Android M Preview 2 is noteworthy in that it supports multi-window mode.
![](https://habrastorage.org/files/076/747/21f/07674721f5504e5a8b29ad95856e27c6.jpg)
Developing multitasking solutions in Android
There are two approaches to working with multiple windows: this is the use of floating (floating) and docked (docked) windows. Among the main possibilities of working in multi-window modes, one can note opening and closing windows (open / close), changing their size (resize) and relative position (swap). Opening or closing a window, we respectively enable or disable multi-window mode. The resize function allows you to adjust the size of the windows. Repositioning windows is an action that allows you to swap them.
![](https://habrastorage.org/files/da6/188/4c6/da61884c63a64e4c81d0d8bc473fb015.jpg)
Multiple Window Modes
In 2013, the market appeared a lot of solutions designed to work with multiple windows. They were developed by OEMs and ODMs, independent software vendors, and the open source community. In the table below you can find a comparison of various technologies for organizing multi-window work in the Android environment.
Android platform code can be modified in order to equip it with support for additional features. Android OS architecture 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 launch, called the “main stack”. As you know, multi-window mode requires more stacks to accommodate multiple windows. As a result, you need to modify the system class ActivityManagerService, adding an interface to it for creating and managing the stack. To modify the platform class WIndowManagerService, which allows you to manage graphical representations of applications, you need to change the InputManager. This is necessary so that he can redirect touch events to the corresponding 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 on various stacks. Support for multiple stacks and the ability to manage them have been added to the system. The figure below shows the differences in working with the stack in different versions of Android.
![](https://habrastorage.org/files/616/8f2/5c9/6168f25c93084627855f09dfaf7af06a.jpg)
Comparison of the work with the stack in Android 4.3 and Android 4.4
Now we will focus on Android 5 (Lollipop). Android OS uses callback mechanisms to perform the interface functions of Activity. However, the control function is implemented at the platform level. Therefore, now we will consider two important classes: ActivityManagerService and WindowManagerService.
![](https://habrastorage.org/files/38c/850/d54/38c850d5470e47d38663061a651232c4.jpg)
Lollipop Platform Software Structure
Since the ability to work in multi-window mode depends on the stack, the following shows how you can create a stack and how to start Activity in this stack. In Lollipop, the following functions have been added to the IactivityManager.java interface:
After starting, the SystemServer process calls the activity management services and windows management services. In order to observe this process, we can add runtime exceptions (RuntimeException) to the appropriate places in the command.
![](https://habrastorage.org/files/30c/9a3/7eb/30c9a37eb0f94b3385ccb0299c008001.jpg)
The process of creating a stack in Lollipop
Now let's see how to start an Activity on the stack:
![](https://habrastorage.org/files/c3e/739/e63/c3e739e6396e4b0292ddd657e5a67628.jpg)
Starting an Activity on a stack
In Lollipop, the following commands were added to the ADB utility (Android Debug Bridge, Android debug bridge):
WindowManagerService is the central part of the window management system. Its functionality includes scheduling input events, controlling the location of objects on the screen and the surfaces on which graphic elements are displayed.
![](https://habrastorage.org/files/43d/dd7/952/43ddd7952b8847679b1374abfdd5be41.jpg)
![](https://habrastorage.org/files/096/512/1ef/0965121ef63e46caab14f7be351ca632.jpg)
Role of WindowsManagerService in Android Graphics Architecture
When working in multi-window mode, resizing windows is available. Examples are known where the size of the window displaying the game animation cannot be resized. The main reason for this is that the Android SurfaceFlinger subsystem cannot dynamically change the size of the output image.
![](https://habrastorage.org/getpro/habr/post_images/9a4/2ef/80f/9a42ef80fcfa34f7ad7840a32c4c6a3d.png)
Games that use SurfaceFlinger cannot dynamically change the window size.
Another problem is that some applications do not display correctly in multi-window mode. In the figure below you can see that the calculator does not display correctly in multi-window mode. It's all about the layout of the application, which is not designed for such conditions of use.
![](https://habrastorage.org/getpro/habr/post_images/7c6/458/d72/7c6458d723d2266f2d0a2eb5c91691d6.png)
Calculator with a layout not designed for multi-window operation
Android M Developer Preview 2 can be launched on Nexus 5, 6, 9 and Nexus Player. If you don’t have such a device, or if you don’t want to install an OS in it in Preview status, you can get acquainted with Android M using the emulator in Android Studio. In particular, now we are interested in standard tools for working in 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 choosing as a system image one of the ones available with the API Level MNC. In our case, it was an x86_64 image. Next, you need to run 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 guide.
Now the fun part. For starters, you can run several applications, everything will be as usual. But if you click on the button for calling up the list of recently opened applications, a new icon will appear in the headers of the window thumbnails. By default, this is a frame that indicates that the application is starting in full screen mode. If you click on this icon, a menu for selecting the layout of the window layout appears.
![](https://habrastorage.org/getpro/habr/post_images/a8e/b0c/918/a8eb0c918b0741a941de235b20e1543e.png)
The menu for choosing the layout of the location of windows in multi-window mode
Then everything is completely clear. Select the desired layout and enjoy the multi-window mode:
![](https://habrastorage.org/getpro/habr/post_images/5e5/699/c80/5e5699c8037376cb697c64f54785e17d.png)
Multi-window mode in Android M
It is still unknown whether multi-window operation 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 good reason to believe that the day is not far off when the adaptation of applications for multi-window mode from a competitive advantage will turn into an urgent need.
If you want to equip your applications designed for earlier versions of Android with support for multiple windows, it's time to turn to the solutions of third-party developers, which were discussed above. For example, to Cornerstone.
Onskreen created Cornerstone, the first framework 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 working 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 find out the technical details of the system.
![](https://habrastorage.org/files/eb5/7b9/949/eb57b99496254d8e8479c3b0ab6499fa.jpg)
Cornerstone Mods on Android Jelly Bean
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 improve products on devices with Intel Architecture (IA). Multi-window support is a good example of a useful feature that gives applications a competitive edge. This is convenient, multi-window mode gives the user the ability to perform several tasks simultaneously. For example, to watch a video and write a review to friends about what they’re watching. For example, play a game and read its reviews. Today, multiple devices support multi-window operation. For example, these are the Ramos i12, Teclast x98, and Cube i7 tablets,
![](https://habrastorage.org/getpro/habr/post_images/aa0/122/11e/aa012211e0f1ccdd512451ad0b3783d6.png)
Multi-window mode on IA devices
» Android 6.0 Muffin Concept Video Shows Multi-Windows, Quick Reply Feats
Thank you for your attention!
If the user has to choose between two applications that are similar in almost everything, but differ in support for simultaneous work with multiple windows, it is not surprising that he will choose what provides such support. From the article you will learn about multi-window mode in Android, and how to use this feature when building your own applications.
![](https://habrastorage.org/files/660/d52/714/660d52714cd141b8b68ac06f30bb0a1f.jpg)
Overview
Simultaneous work with multiple windows in Android is an interesting feature that can distinguish your application from many others, give it an additional competitive advantage. Many OEMs and ODMs, such as Samsung, Ramos, and Huawei, are modifying the base Android system. In particular, they are introducing multi-window support. 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 such a function.
![](https://habrastorage.org/getpro/habr/post_images/b88/a01/c31/b88a01c3172f1f0d5cf6d46a6225dc6a.png)
Scenarios for using multi-window mode
Preliminary 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. From 2013 to the present, you can observe the explosive growth of solutions to support the simultaneous work with multiple windows in Android.
In May 2015, Android M Developer Preview was released (today, in July, Preview 2 is already available). The official release of Android M (6.0) is expected in the fall of 2015. Among other innovations, Android M Preview 2 is noteworthy in that it supports multi-window mode.
![](https://habrastorage.org/files/076/747/21f/07674721f5504e5a8b29ad95856e27c6.jpg)
Developing multitasking solutions in Android
There are two approaches to working with multiple windows: this is the use of floating (floating) and docked (docked) windows. Among the main possibilities of working in multi-window modes, one can note opening and closing windows (open / close), changing their size (resize) and relative position (swap). Opening or closing a window, we respectively enable or disable multi-window mode. The resize function allows you to adjust the size of the windows. Repositioning windows is an action that allows you to swap them.
![](https://habrastorage.org/files/da6/188/4c6/da61884c63a64e4c81d0d8bc473fb015.jpg)
Multiple Window Modes
In 2013, the market appeared a lot of solutions designed to work with multiple windows. They were developed by OEMs and ODMs, independent software vendors, and the open source community. In the table below you can find a comparison of various technologies for organizing multi-window work in the Android environment.
Product | Cornerstone | Standout | Xposed | Tieto |
Description | Android multitasking framework | An open source library that can be used to create floating window applications. | A multi-window application that supports docked windows | The project aims to create a desktop environment resembling work on a desktop PC |
Support for opening, closing windows, resizing, expanding to full screen | Yes | Yes | Yes | Yes |
Window style | Fixed | Floating | Fixed | Docked and floating |
Code modification | Android platform level | Application level | Android platform level | Android platform level |
Application support | All applications are supported, however, SurfaceView dynamic configuration is not available. | Some supporting applications. For example, a calculator. | The 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
Android platform code can be modified in order to equip it with support for additional features. Android OS architecture 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 launch, called the “main stack”. As you know, multi-window mode requires more stacks to accommodate multiple windows. As a result, you need to modify the system class ActivityManagerService, adding an interface to it for creating and managing the stack. To modify the platform class WIndowManagerService, which allows you to manage graphical representations of applications, you need to change the InputManager. This is necessary so that he can redirect touch events to the corresponding 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 on various stacks. Support for multiple stacks and the ability to manage them have been added to the system. The figure below shows the differences in working with the stack in different versions of Android.
![](https://habrastorage.org/files/616/8f2/5c9/6168f25c93084627855f09dfaf7af06a.jpg)
Comparison of the work with the stack in Android 4.3 and Android 4.4
Now we will focus on Android 5 (Lollipop). Android OS uses callback mechanisms to perform the interface functions of Activity. However, the control function is implemented at the platform level. Therefore, now we will consider two important classes: ActivityManagerService and WindowManagerService.
![](https://habrastorage.org/files/38c/850/d54/38c850d5470e47d38663061a651232c4.jpg)
Lollipop Platform Software Structure
Managing Activity at Lollipop
Since the ability to work in multi-window mode depends on the stack, the following shows how you can create a stack and how to start Activity in this stack. In Lollipop, the following functions have been added to the IactivityManager.java interface:
New features of the IactivityManager.java interface | Description |
public void moveTaskToStack (int taskId, int stackId, boolean toTop) | Move task to another stack |
public void resizeStack (int stackBoxId, Rect bounds) | Resize Stack |
public void setFocusedStack (int stackId) | Set focus to the selected task |
Public Boolean isInHomeStack (int taskId) | Find out if a task is in HomeStack |
After starting, the SystemServer process calls the activity management services and windows management services. In order to observe this process, we can add runtime exceptions (RuntimeException) to the appropriate places in the command.
![](https://habrastorage.org/files/30c/9a3/7eb/30c9a37eb0f94b3385ccb0299c008001.jpg)
The process of creating a stack in Lollipop
Now let's see how to start an Activity on the stack:
![](https://habrastorage.org/files/c3e/739/e63/c3e739e6396e4b0292ddd657e5a67628.jpg)
Starting an Activity on a stack
In Lollipop, the following commands were added to the ADB utility (Android Debug Bridge, Android debug bridge):
ADB team | Function | Description |
Adb shell am stack start | Launches a new Activity on | In Kitkat 4.4, ADB commands contain: adb shell am stack create In Lollipop 5.0: adb shell am stack create deletion |
Adb shell am stack movetask | Moves | Usage: adb shell am stack movetask task_id stackid true / false Note: this works in Kitkat, but not in Lollipop |
Adb shell am stack resize | Resize stack | Usage: adb shell am stack resize task_id weight |
Window Management in Lollipop
WindowManagerService is the central part of the window management system. Its functionality includes scheduling input events, controlling the location of objects on the screen and the surfaces on which graphic elements are displayed.
![](https://habrastorage.org/files/43d/dd7/952/43ddd7952b8847679b1374abfdd5be41.jpg)
![](https://habrastorage.org/files/096/512/1ef/0965121ef63e46caab14f7be351ca632.jpg)
Role of WindowsManagerService in Android Graphics Architecture
Multi Window Issues
When working in multi-window mode, resizing windows is available. Examples are known where the size of the window displaying the game animation cannot be resized. The main reason for this is that the Android SurfaceFlinger subsystem cannot dynamically change the size of the output image.
![](https://habrastorage.org/getpro/habr/post_images/9a4/2ef/80f/9a42ef80fcfa34f7ad7840a32c4c6a3d.png)
Games that use SurfaceFlinger cannot dynamically change the window size.
Another problem is that some applications do not display correctly in multi-window mode. In the figure below you can see that the calculator does not display correctly in multi-window mode. It's all about the layout of the application, which is not designed for such conditions of use.
![](https://habrastorage.org/getpro/habr/post_images/7c6/458/d72/7c6458d723d2266f2d0a2eb5c91691d6.png)
Calculator with a layout not designed for multi-window operation
Support for multi-mode in Android M
Android M Developer Preview 2 can be launched on Nexus 5, 6, 9 and Nexus Player. If you don’t have such a device, or if you don’t want to install an OS in it in Preview status, you can get acquainted with Android M using the emulator in Android Studio. In particular, now we are interested in standard tools for working in 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 choosing as a system image one of the ones available with the API Level MNC. In our case, it was an x86_64 image. Next, you need to run 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 guide.
Now the fun part. For starters, you can run several applications, everything will be as usual. But if you click on the button for calling up the list of recently opened applications, a new icon will appear in the headers of the window thumbnails. By default, this is a frame that indicates that the application is starting in full screen mode. If you click on this icon, a menu for selecting the layout of the window layout appears.
![](https://habrastorage.org/getpro/habr/post_images/a8e/b0c/918/a8eb0c918b0741a941de235b20e1543e.png)
The menu for choosing the layout of the location of windows in multi-window mode
Then everything is completely clear. Select the desired layout and enjoy the multi-window mode:
![](https://habrastorage.org/getpro/habr/post_images/5e5/699/c80/5e5699c8037376cb697c64f54785e17d.png)
Multi-window mode in Android M
It is still unknown whether multi-window operation 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 good reason to believe that the day is not far off when the adaptation of applications for multi-window mode from a competitive advantage will turn into an urgent need.
If you want to equip your applications designed for earlier versions of Android with support for multiple windows, it's time to turn to the solutions of third-party developers, which were discussed above. For example, to Cornerstone.
Example: Cornerstone
Onskreen created Cornerstone, the first framework 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 working 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 find out the technical details of the system.
![](https://habrastorage.org/files/eb5/7b9/949/eb57b99496254d8e8479c3b0ab6499fa.jpg)
Cornerstone Mods on Android Jelly Bean
Summary
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 improve products on devices with Intel Architecture (IA). Multi-window support is a good example of a useful feature that gives applications a competitive edge. This is convenient, multi-window mode gives the user the ability to perform several tasks simultaneously. For example, to watch a video and write a review to friends about what they’re watching. For example, play a game and read its reviews. Today, multiple devices support multi-window operation. For example, these are the Ramos i12, Teclast x98, and Cube i7 tablets,
![](https://habrastorage.org/getpro/habr/post_images/aa0/122/11e/aa012211e0f1ccdd512451ad0b3783d6.png)
Multi-window mode on IA devices
For home reading
» Android 6.0 Muffin Concept Video Shows Multi-Windows, Quick Reply Feats
Thank you for your attention!