Developer tip: launch on adjacent screen
Hello Android developers,
Last year we blogged about bringing your existing apps to the Microsoft Surface Duo, which included a variety of suggestions from simple tweaks to a set of user-experience design patterns that you could use to enhance your applications’ UI. Today I’m going to re-visit one of those dual-screen enhancement tips that’s easy to incorporate into your existing apps; launching new intents on the second screen.
This behavior builds on an intent launch flag that works on any device that supports Android multi-windowing. It’s mentioned in the Android multi-window developer documentation, launching activities adjacent to the current activity. By adding the Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT flag (available since API level 24) when starting a new activity, you’re asking the operating system to open it next to the existing activity, if possible, keeping both activities visible.
The following screenshots demonstrate how this works using our IntentToSecondScreen sample code. When the second screen is empty (i.e.. the launcher is visible), adding this flag will cause a new activity to be started on the other screen:
Figure 1: If the second screen is free, the second activity opens there
When the second screen is occupied on Surface Duo, the new activity will open over the existing one (the same behavior you would expect on a single screen):
Figure 2: If the second screen is in use, the second activity opens over the first
Note that other devices that support multi-windowing may not require the adjacent space to be empty, but instead open over an existing app view.
The above sample is available for download in Kotlin or Java. The following snippet shows how to add the flag to your code. It also uses the FLAG_ACTIVITY_NEW_TASK flag which ensures the activity will become the start of a new task on this history stack.
val intent = Intent(this, SecondActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(intent)
Intent intent = new Intent(this, SecondActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
You can see a real-world example of this behavior in Outlook for Android. By default, when replying to an email, Outlook shows a threaded view of the email with the reply underneath the original text. By pressing the dual-screen button, Outlook will open the reply activity on the adjacent screen:
Figure 3: Outlook opening the compose activity on the second screen
Outlook also adapts its layout dynamically when the app is spanned over both screens, which is something you can also do with your apps. You can learn more about the different dual-screen app patterns in our docs.
Feedback and resources
The launch adjacent flag is one way to add basic multi-window support to your app.
Check out the Surface Duo developer documentation and past blog posts for other ideas for enhancing your apps for the Surface Duo and other dual-screen devices.
If you have any questions, or would like to tell us about your apps, use the feedback forum or message us on Twitter @surfaceduodev.