Reputation: 7653
I have a project using secondary display, using Presentation API. It works with emulator with Android 10, device with Android 9 but not with emulator with Android 11 or 12.
On emulator, I create secondary display as shown on picture:
Here my activity:
class MainActivity : AppCompatActivity() {
private var presentation: Presentation? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
if (displayManager.displays != null && displayManager.displays.size > 1) {
val display = displayManager.displays[1]
presentation = TestPresentation(this, display)
}
}
override fun onResume() {
presentation?.show()
super.onResume()
}
override fun onPause() {
presentation?.hide()
super.onPause()
}
}
And my presentation
class TestPresentation(context: Context, display: Display): Presentation(context,display)
{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.presentation_layout)
}
}
On Android 11 or greater, I've got this error:
2022-03-21 22:44:55.458 3563-3563/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.testpresentation2, PID: 3563 java.lang.RuntimeException: Unable to resume activity {com.example.testpresentation2/com.example.testpresentation2.MainActivity}: android.view.WindowManager$InvalidDisplayException: Unable to add window android.view.ViewRootImpl$W@9b166b1 -- the specified display can not be found at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4444) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: android.view.WindowManager$InvalidDisplayException: Unable to add window android.view.ViewRootImpl$W@9b166b1 -- the specified display can not be found at android.view.ViewRootImpl.setView(ViewRootImpl.java:1096) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at android.app.Dialog.show(Dialog.java:340) at android.app.Presentation.show(Presentation.java:257) at com.example.testpresentation2.MainActivity.onResume(MainActivity.kt:35)
Upvotes: 4
Views: 934
Reputation: 7653
There's a bug in AVD/Emulator.
Emulator extended control needs to support passing flags for the display setup. A display needs to explicitly specify FLAG_PRESENTATION in order to be a valid target for a presentation.
Issue open on google tracker: https://issuetracker.google.com/issues/227218392
Upvotes: 2