Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Launch the Same Activity Into a Separate Window in Android N Multi-Window?

The docs for the Android N Developer Preview 1 indicate that you can use Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT to request that Android launch an activity into a separate window (freeform) or an adjacent pane (split-screen). Google's sample code shows using Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK to accomplish this.

This works fine, if the activity being started is a different class than the one doing the starting.

So, for example, if you have a MainActivity that has the following code to launch a separate instance of itself:

  Intent i=
    new Intent(this, MainActivity.class)
      .setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |
        Intent.FLAG_ACTIVITY_NEW_TASK);

  startActivity(i);

then the result is that FLAG_ACTIVITY_LAUNCH_ADJACENT is ignored and the new activity instance goes into the existing window or pane.

If, however, you launch any other activity (e.g., SecondActivity.class), then FLAG_ACTIVITY_LAUNCH_ADJACENT works as advertised.

What if you want to allow the user to open two spreadsheets, two notepads, or two of whatever-it-is from your app? How can we use FLAG_ACTIVITY_LAUNCH_ADJACENT to launch two instances of the same activity?

like image 404
CommonsWare Avatar asked Mar 14 '16 11:03

CommonsWare


People also ask

How do I open the same app in split screen Android?

Step 1: Tap & hold the recent button on your Android Device –>you will see all the recent list of applications listed in chronological order. Step 2: Select one of the apps you wish to view in split screen mode –>once the app opens, tap & hold the recent button once again –>The screen will split into two.

How do I switch between multi windows?

You can use Flip to switch between open windows. To do this, press and hold the Alt key on your keyboard, then press the Tab key. Continue pressing the Tab key until the desired window is selected.


1 Answers

According to the discussion on this issue, you also need to blend in FLAG_ACTIVITY_MULTIPLE_TASK:

  Intent i=
    new Intent(this, MainActivity.class)
      .setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |
        Intent.FLAG_ACTIVITY_NEW_TASK |
        Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

  startActivity(i);

Then the two activity instances will be in separate windows/panes/whatever.

This sample project demonstrates this for the N Developer Preview 1.

like image 183
CommonsWare Avatar answered Oct 22 '22 02:10

CommonsWare