Skip to content

Instantly share code, notes, and snippets.

@huuphuoc1396
Last active October 19, 2020 07:49
Show Gist options
  • Save huuphuoc1396/875a15d136e21a94490fe979a6fa523c to your computer and use it in GitHub Desktop.
Save huuphuoc1396/875a15d136e21a94490fe979a6fa523c to your computer and use it in GitHub Desktop.
Start secondary activity
if (displays.size > 1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Activity options are used to select the display screen.
val options = ActivityOptions.makeBasic()
// Select the display screen that you want to show the second activity
options.launchDisplayId = displays[1].displayId
// To display on the second screen that your intent must be set flag to make
// single task (combine FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK)
// or you also set it in the manifest (see more at the manifest file)
startActivity(
Intent(this@MainActivity, SecondActivity::class.java),
options.toBundle()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment