1

I configured a secondary display for my android device. By default, the secondary display will mirror the content of the main diaplsy.

Then I use DisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION) to get secondary displayId and use ActivityOptions to start an Activity on secondary display, then it changes from mirror mode to show my Activity page.

Now I have a need to switch secondary display back to mirror mode without finish Activity, but I can't find any API to switch back to mirror mode. So is there any way to flexibly switch the display mode of the secondary display?

My start Activity on secondary display code like this:

        val displays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
        val secondaryDisplay = displays.firstOrNull()
        if (secondaryDisplay != null) {
            val displayId = secondaryDisplay.displayId
            val context = activity.createDisplayContext(secondaryDisplay)
            val intent = Intent(context, activityClazz)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

            if (isActivityStartAllowedOnDisplay(context, displayId, intent)) {
                val ops = ActivityOptions.makeBasic().apply { launchDisplayId = displayId }
                context.startActivity(intent, ops.toBundle())
            } else {
                Log.e(TAG, "Cannot start activity to secondary display: $displayId")
            }
        }
陈朝勇
  • 23
  • 4
  • Why are you trying to avoid finishing the activity? – CommonsWare Sep 18 '21 at 11:33
  • you can assume there is a button on main display to switch secondary display between mirror mode and activity mode, so the opend activity can't finish – 陈朝勇 Sep 20 '21 at 02:17
  • 1
    My guess is that you are better off using `Presentation`, as you get more control that way. The `ActivityOptions` approach is simpler to use but is designed for simple scenarios. – CommonsWare Sep 20 '21 at 11:03

0 Answers0