Multi-Window/Split-Screen In Android

debabrata

Multi-window / split-screen in Android

Android Nougat (version 7.0, API level 24) has added multi-window feature for displaying multiple apps on the same screen. On mobile and tablet devices, two apps can run side-by-side or one-above-the-other in split-screen mode. Also, on TV, apps can use picture-in-picture mode and in larger devices, apps can use freeform mode in addition to split-screen mode. Here, we would discuss about multi-window mode only on handheld devices.

 

How to switch to multi-window mode in a handheld device?

  • When the user opens the overview screen and performs a long press on an Activity title, the user can drag the Activity to the top of the screen (which reads Drag here to use split screen”) to put it in the multi-window mode.
  • When the user performs a long press on the overview button, the device puts the current Activity in the multi-window mode, and opens the overview screen to let the user choose another Activity to share the screen.

 

How to configure the app for multi-window mode?

  • When the app targets API level 23 or lower (which doesn’t support multi-window mode):
  1. If the app has fixed orientation:  When the user tries to open the app in the multi-window mode, the app opens in the full screen.
  2. If the app has multi-orientation: When the user opens the app in the multi-window mode, the system forcibly resizes the app; also the system warns the user that the app might behave unexpectedly.
  • When the app targets API level 24 or higher: You can configure how and whether your app’s Activities support multi-window mode. Set the following attribute in your manifest’s <activity> or <application> element 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 mode. If the

          attribute is set to false, the Activity does not support multi-window mode and when the

          user attempts to launch the Activity in multi-window mode, the Activity opens in the full

          screen. Note that a root Activity’s attribute settings apply to all Activities within its task

          stack. Also note that if you do not specify a value for this attribute, the attribute’s value

         defaults to true.

You can enable the multi-window mode in the AndroidManifest.xml in the following way:

<manifest …>

    …

    <application …>

        <activity android:name=”.MainActivity”

           android:label=”@string/app_name”

           android:resizeableActivity=”true” …>

        …

        </activity>

        …

    </application>

</manifest>

 

How does multi-window affect the Activity lifecycle?

Multi-window mode doesn’t affect the Activity lifecycle. Only the most recently interacted Activity is active (i.e. executing it’s onResume() method) and other Activity is visible but inactive (i.e. executing its onPause() method). In this situation, sometimes, an inactive Activity might need to continue running; for example, an Activity which shows a video, should not pause the video while executing onPause() method; instead the Activity should pause the video in onStop(), and resume playback in onStart().

When an app enters the multi-window mode, the system notifies its Activity of configuration changes. Also, when the user resizes the app in the split-screen, or puts the app back into full-screen mode, the Activity is notified of the runtime changes. Either the Activity can handle the configuration change itself, or it can allow the system to destroy the Activity and recreate it with the new dimensions.

How does the system notify the app about the multi-window change?

The system calls the onMultiWindowModeChanged() method whenever the Activity goes into or out of multi-window mode.

Google Certified Agency

How to launch new Activities in the multi-window mode?

In the multi-window mode, you can request the system to launch the new Activity in the adjacent window in the following way:

private void launchNextActivity() {

  Intent intent = new Intent(this, NextActivity.class);

  intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |

          Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

  startActivity(intent);

}

The system is not guaranteed to be able to do this, but it makes the Activity adjacent if possible. If the device is not in split-screen mode, this flag has no effect. Note that 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.

 

What are the constraints in the multi-window mode?

  • Some System UI customization options are disabled; for example, apps cannot hide the status bar if they are not running in full-screen mode.
  • The system ignores changes to the android:screenOrientation attribute.

 

What are the things you need to keep in mind while testing the multi-window mode?

As a developer, you’ve to test your app very carefully and thoroughly in the full-window, split-window and resized-window to check following

  1. App is behaving as expected
  2. User experience is acceptable
  3. App-switching is happening properly
  4. App is navigating properly
  5. App’s essential functionality is visible
  6. App’s texts are readable and the UI elements aren’t too small to interact with
  7. Video continues to play in the inactive split-window while the user is interacting with another app
  8. App has any performance issue (lagging, leaking memory, etc.)
  9. App is crashing.

 

Is your app suitable for multi-window mode?

The multi-window feature has some advantages as well as some complexities. Good things are that the user can do multitasking on multiple apps at the same time, can do drag-and-drop data from one Activity to another. But if you think that your app might not behave properly as there would be less functional area in the split-screen, you might disable the multi-window mode for you app; for example, some gaming apps might not be suitable for multi-window mode.

Click the image below to download your free eBook.

Quick Guide to Planning Your Mobile Strateg

about the author

debabrata