Display your app on multi-screen at the same time in Android

Tram Ho

Display your app on multi-screen at the same time by using multi-display in Android.

Overview

Android 10 or higher version supported to display other activities on many external screens, and they are named multi-display which are used for foldable phones as well as a secondary screen is connected with your device.

Today, I will introduce with you about how to display an activity on another screen, and the SDK’s LG for the LG V50 to tracking event for this foldable phone with its cover secondary screen.

Display your activity on another screen

Declare your secondary activity in the manifest

launchMode is singleTask which combine between FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK set in your intent when you start an activity. Cause for using these flags is to run your activity on the new task.

Besides, I have an attribute that is taskAffinity. If your activity just use the FLAG_ACTIVITY_NEW_TASK flag that taskAffinity isn’t set, it start on the same task with other activities. However, if you set taskAffinity for your activity, it would run on the new task and activities have a same taskAffinity will run together.

Start your activity

Firstly, you need a DisplayManager which manages the properties of attached displays.

Next, you use it to take all display connected with the device.

Ensure that your device has than more two-display then create activity options by the ActivityOptions class to indicate the display ID that you would like to show your activity.

Now, you can run your activity on another screen.

LG Dual Screen SDK

What’s the LG Dual Screen?

The LG Dual Screen is a mobile handset with two screens. Independent applications can be run on the screens at the same time.

It has an SDK to support for tracking folding events.

Callbacks

This SDK have two major callbacks:

  • CoverDisplayCallback: Handle events related to states such as cover is enabled, disabled or dismounted.

  • SmartCoverCallback: This callback help indicate when your cover is opened, closed or flip over.

DisplayManagerHelper

DisplayManagerHelper is provided by SDK used to register above callbacks as well as determine your device is an LG dual screen or not.

You can construct this class with the current context. If it’s successful, your activity isn’t the LG dual screen device. Otherwise, you can register your callbacks through two-function are registerCoverDisplayEnabledCallback(key: String, callback: CoverDisplayCallback) and registerSmartCoverCallback(callback: SmartCoverCallback)

Finally, you should remove all callbacks when your activity or fragment is destroyed to certain that isn’t occur a memory leak.

Demo

You can see my multi-screen demo on GitHub. If it’s helpful with you, lets a star for me.
alt

References

  1. https://developer.android.com/guide/topics/ui/foldables?#multi-display
  2. https://developer.android.com/reference/android/hardware/display/DisplayManager
  3. http://mobile.developer.lge.com/develop/sdks/lg-dual-screen-sdk/
Share the news now

Source : Viblo