How to run the same action in a separate window in Android N multiscreen mode?

The docs for Android N Developer Preview 1 show that you can use Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT to request Android activity to start in a separate window (free form) or an adjacent panel (split screen). Sample Google code shows using Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK to accomplish this.

This works great if the running activity is a different class than the one that makes the launch.

So, for example, if you have MainActivity , which has the following code to run 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 ignored, and the new activity instance goes into an existing window or panel.

If, however, you trigger any other action (for example, SecondActivity.class ), then FLAG_ACTIVITY_LAUNCH_ADJACENT works as advertised.

What if you want to allow the user to open two tables, two notebooks or two of them? How can we use FLAG_ACTIVITY_LAUNCH_ADJACENT to start two instances of the same activity?

+5
source share
1 answer

According to the discussion of this problem , you also need to add to 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 two instances of activity will be in separate windows / panels / independently.

This sample project demonstrates this for N Developer Preview 1.

+6
source

Source: https://habr.com/ru/post/1245005/


All Articles