Wednesday, 9 November 2022

Android: Failing to open an activity in adjacent screen in multiwindow

I have two of my activities (same app) opened in multiwindow / split-screen. Now I want that when a user taps on a button on Screen-1, I want to open an activity in Screen-2.

I have read Android's document and I think I am doing it right, but it is not working. It still opens the new activity in Screen-1. Here is my code:

   val intent = Intent(this, MyActivity::class.java)
   intent.addFlags( Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or FLAG_ACTIVITY_NEW_TASK)
   startActivity(intent)

I have set

android:resizeableActivity="true"

in the manifest, under the "application" tab, also in the "activity" tag.

What wrong am I doing?

I also tried this:

       val intent = Intent(Intent.ACTION_VIEW) 
       intent.data = Uri.parse(MyActivity::class.java.name)
       intent.addFlags( Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or FLAG_ACTIVITY_NEW_TASK)
       startActivity(intent)

didn't work.

Another related question I want to ask is, is FLAG_ACTIVITY_NEW_TASK required? what if I don't want to create a new task?



from Android: Failing to open an activity in adjacent screen in multiwindow

No comments:

Post a Comment