HomeAndroidLeverage Multi-Window and Exercise Embedding | by Roberto Orgiu | Android Builders...

Leverage Multi-Window and Exercise Embedding | by Roberto Orgiu | Android Builders | Mar, 2023


With Android 12L, we put an effort into making apps higher on giant screens, and with Android 13 we launched extra new alternatives to boost the expertise you may present to your customers. In a world with elevated display actual property, multitasking is necessary, and listed here are two methods you may leverage it:

You most likely already know that your customers can get simply into multi-window mode with a easy gesture, however you can begin multi-window mode your self by utilizing the Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT flag within the intent used to launch the goal app:

This operate will launch OtherActivity adjoining to yours in multi-window, in order that it may leverage multitasking. One piece of recommendation: it will work on each gadget operating Android 7 and newer, and it’ll cut up the display into two halves, both vertically or horizontally, primarily based on the gadget. Moreover, ranging from Android 12L, utilizing the resizableActivity="true"flag won’t choose out from multi-window.

How multi-window seems on telephones and tablets

Many apps means many architectures, however there could be instances the place that you must launch one other app from yours for various and beneficial causes. As an example, your corporation could be targeted on completely different providers that may work collectively, like a file supervisor and a spreadsheet app, a information studying and a sports activities information app, streaming media and a chat app, and so forth.

You’re most likely already acquainted with exercise embedding (if not, be certain that to take a look at this speak), and in Android 13, we launched the potential of launching actions from different apps as in the event that they originated from your personal app.

Since embedding different apps’ actions make them seem as if they’re part of your app, there are extra safety necessities to make use of this type of embedding. At first, enabling exercise embedding throughout apps is an opt-in characteristic, that means that the embedded app must take motion to be embedded.

The embedded app can opt-in by:

  • permitting any and each app to embed the exercise, and performing any belief verification at runtime
  • embedding an inventory of certificates within the XML assets and Android will solely enable apps signed with a kind of certificates to embed it

Within the pattern on GitHub, you will notice find out how to let any app embed yours and find out how to embed an exterior app in yours. However on this instance, no security examine might be carried out, because the objective of this put up is to clarify how the API works and how one can troubleshoot points that may come up.

Let’s begin from the app you need to embed. To permit everybody to embed an exercise, that you must make the exercise seen from outdoors the APK. Thus, that you must set the exported flag to true, and that you must add the next line to the manifest, in order that it seems like this:

The final line is the one which tells Android that your exercise could be embedded.

Notice: Keep in mind, for the aim of this weblog put up, you aren’t organising any safety measures.

Now that you’ve got your app able to be embedded, it’s time to embed it in one other app of yours!

For the sake of readability, you may consider the embedded app because the visitor and the embedding app because the host.

Very first thing that you must do is add the next dependencies to the host app’s construct.gradlefile:

Subsequent, that you must create a cut up configuration that may mean you can outline which Exercise you need to embed utilizing its certified identify:

The SplitPairRule defines the habits of the 2 actions when one finishes, guaranteeing the navigation you plan. On this case, if the host exercise finishes, the visitor will end as effectively, however it gained’t be the identical in case the visitor finishes first. Subsequent, the rule defines the breakpoint for displaying the actions aspect by aspect, which is 600dp on this case. Lastly, you outline the cut up ratio from 0 to 1; 0.3 signifies that the host exercise will take 30% of the out there area on display, and the visitor exercise will take up the remainder of the out there area.

The SplitPairFilter defines what actions are concerned, utilizing the straightforward identify for the host, and the certified identify for the visitor.

Moreover, you may declare a placeholder that might be introduced earlier than the visitor exercise is began or after it’s completed, by utilizing the SplitPlaceholderRule:

At this level, that you must create the startup initializer that may load the cut up configuration:

Then, that you must add the initializer to the AndroidManifest file of the host app to make it discoverable:

The very last thing that you must do is name the visitor Exercisefrom the host app:

If you wish to know extra about exercise embedding, take a look at the pattern on GitHub, the video from Android Dev Summit ’22, and the Exercise embedding developer information.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments