Multi-display Android
In Android there are also multi-window, multi-screen and multi-display concept. They are different: multi-window is to show multiple window in one application, for this you need to change the AndroidManifest.xml; multi-screen is normally about supporting different screen-sizes. This article is about Multi-display which does connect Android device with another display/screen, and show content independently.
First Connect the Android device with the secondary display
Connect Android device(at least Android 8) to a secondary monitor using a USB to HDMI adapter like the ones we use to connect computer to external display.
By default, the Android should screen should be mirrored to the external monitor.
Trouble shooting:
For some Samsung device, it may automatically start Samsung Dex. In this case, you should disable Samsung Dex in settings->connections→More Connection settings→ HDMI mode→ MirrorLink
If the mirroring doesn’t work, try change a newer adapter. The one worked for me is StarTech USB C to HDMI adapter.
Then add the below code in your app
You can get the display(screen) info from DisplayManager. And set the display id to the second Activity when startActivity.
val displays = (getSystemService(Context.DISPLAY_SERVICE) as DisplayManager).displays
Get Mei Dong’s stories in your inbox
Join Medium for free to get updates from this writer.
val options = ActivityOptions.makeBasic()
if (displays.size >= 2) {
options.launchDisplayId = displays[1].displayId
startActivity(Intent(this, SecondActivity::class.java), options.toBundle())
}
So far I have found the display[0] is main screen, and the display[1] is the external monitor.
For ClusterActivity, you should set it as singleInstance in AndroidManifest.xml
<activity
android:name="com.app.SecondActivity"
android:launchMode="singleInstance"
android:taskAffinity="" />





