14

In this sample project, my MainActivity has code to launch a separate activity on an external display, using setLaunchDisplayId() on ActivityOptions:

class MainActivity : AppCompatActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    getSystemService(DisplayManager::class.java)
      .getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
      .firstOrNull()
      ?.let { display ->
        Intent(this, ExternalDisplayActivity::class.java)
          .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
          .let { intent ->
            ActivityOptions.makeBasic()
              .setLaunchDisplayId(display.displayId)
              .toBundle()
              .let { opts ->
                startActivity(intent, opts)
              }
          }
      }
  }
}

ExternalDisplayActivity launches fine onto the external display. However; it shows up in portrait mode, not landscape. This occurs both using a real monitor and a simulated external display from Developer Options in Settings.

Strangely enough, this comes despite the fact that I have android:screenOrientation="landscape" on the ExternalDisplayActivity manifest entry and I request landscape at runtime:

class ExternalDisplayActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContentView(R.layout.activity_external)
    requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
  }
}

landscape works if I use a Presentation and that older API, but I cannot figure out how to get landscape working with the setLaunchDisplayId() route.

Luis Cadena
  • 102
  • 1
  • 2
  • 15
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    There is no problem starting the second activity in either landscape or portrait mode on primary display. I'll check with external displays. – Sina Jan 04 '20 at 07:04
  • That behaviors is a bit surprising, regardless, setting the Orientation to landscape on the other activity is not so bad! and also did you check the difference between the two API's perhaps that solution is there, also can you tried adding android:configChanges="orientation|screenSize|keyboardHidden" in your manifest, which will still make you go back to the receiving activity to configure the orientation manually, but that should tell if there is some kind of configuration changes that you're not aware off and so you might have to go with the solution you have. – Wale Jan 07 '20 at 16:27

0 Answers0