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

399 Views Asked by At

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?

2

There are 2 best solutions below

5
coroutineDispatcher On

I think you should also include:

Intent.FLAG_ACTIVITY_MULTIPLE_TASK

In the or of your intent flags.

0
Thazin Soe On

One possible solution is that do a software update on your testing device.

I also got the same situation the code is fine according to the document but it does work properly. When I try to do a software update on my testing device, that problem goes. ^^)