CLEVELAND, UNITED STATES

675 Alpha Dr, Suite E, Highland Heights,
OH – 44143
Cleveland, Ohio
Tel: +1 512 999 5796

DUBAI, UNITED ARAB EMIRATES

Createc Smart Digital Solutions LLC
PO Box 13334
Dubai, UAE
Tel: +971 557 157 733

KOCHI, INDIA

#102, First Floor Lulu Cyber Tower
Infopark, Kochi – 682 042
Kerala, India
Tel: +91 484 404 5555

×

MAKE YOUR ENQUIRIES

INDIA

+914844045555

USA

+1 512 999 5796

Contact

android_n_windowbnner

Google has released a Developer Preview of Android N on March 9, two months earlier than expected. There has been some interesting features which offers a competitive edge for the Android platform. I am an Android enthusiast who loves some coding. Let’s have look at what Android N delivers in both user and developer perspective. Multi-Window has been the much awaited feature in the list considering the increased mobile landscape. It simply allow users to open two apps on the screen simultaneously. Once I have been a proud owner of 3.5’’ Sony Xperia U, on which I can’t imagine two apps sharing the screen at once. Now the game has changed and mobile manufactures are in a race to merge the barrier between phones and tablets.

app_img 

Android N allows several apps to share the screen at once. For example, a user could split the screen, googling something on the left side while composing an email on the right side. As described in the Android developers page, the user experience depends on the device. Handheld devices running Android N offer split-screen mode. In this mode, the system fills the screen with two apps, showing them either side-by-side or one-above-the-other. The user can drag the dividing line separating the two to make one app larger and the other smaller.

On Nexus Player running Android N, apps can put themselves in picture-in-picture mode, allowing them to continue showing content while the user browses or interacts with other apps.

Manufacturers of larger devices can choose to enable freeform mode, in which the user can freely resize each activity. If the manufacturer enables this feature, the device offers freeform mode in addition to split-screen mode. User can enter the multi-window mode by long pressing the overview button, while we have already one app in the foreground. Another way to enter this mode is long pressing activity title from the overview screen itself. User can drag the selected activity to a highlighted portion of the screen. We should consider the behaviour If you build a multi-orientation app with a version of the SDK lower than Android N, and the user uses the app in multi-window mode, the system forcibly resizes the app. The system presents a dialog box warning the user that the app may behave unexpectedly. The system does not resize fixed-orientation apps; if the user attempts to open a fixed-orientation app under multi-window mode, the app takes over the whole screen. Now let’s move on to developer’s take on the feature. 

Multi-Window Lifecycle 

The activities life cycle in the multi-window mode remains the same. The activity which have the recent user interaction is considered as the foreground activity. All other activities will be in paused state including the one which shares the screen. The system gives higher priority for these paused-but-visible activities than the paused activities that went to background. There is a special scenario that should be handled considering the multi-window mode. We don’t want to pause the video, when an activity is paused-but-visible state in shared screen mode. It should continue playing the video, for which we have to move the code that pauses the video from onPause() to onStop(). Similarly resuming the playback should be moved to onStart() instead of onResume(). 

Setting up the Multi-Window mode in your application 

We should set certain attributes in our manifest file to enable Multi-window mode. android:resizeableActivity Set this attribute in your manifest's or node to enable or disable multi-window display: 

appl_1 

If this is set to true, the activities will be available in Multi-Window mode. If this is set to false, and user launches the app in this mode, app will open in full screen. The default value for this attribute is true. android:supportsPictureInPicture Set this attribute in your manifest's node to indicate whether the activity supports picture-in-picture display. This attribute is ignored if android:resizeableActivity is false. 

appl_2 

Layout attributes With Android N, the manifest element supports several attributes that affect how an activity behaves in multi-window mode: Let’s consider the following 

appl_3 

It shows how to specify an activity's default size and location, and its minimum size, when the activity is displayed in freeform mode. I assume each attributes are self - explanatory. 

Multi-window change notification and querying 

The following new methods have been added to the Activity and Fragment class to support multi-window display. inMultiWindow() 

appl_4 

inPictureInPicture() 

appl_5 

onMultiWindowChanged() 

appl_6 

onPictureInPictureChanged() 

appl_7 

Entering picture-in-picture mode 

To put an activity in picture-in-picture mode, call the new method Activity.enterPictureInPicture(). This method has no effect if the device does not support picture-in-picture mode. 

Launch New Activities in Multi-Window Mode 

When we start an activity using Intents , we can say the system that the new activity should be launched in shared-screen mode adjacent to current one. It can be done by using the flag Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT. 

Supporting drag and drop 

Another interesting aspect of the multi window functionality is that we can drag and drop data from one Activity to another. For making this possible N Preview SDK extends the android.view package to support cross-app drag and drop. That is all we have regarding the Multi-Window support from the Android developers official documentation.

SHARE THIS BLOG ON

test

STAY UP-TO-DATE WITH US

Subscribe to our newsletter and know all that’s happening at Cabot.

SHARE