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.
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.
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().
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:
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.
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
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.
The following new methods have been added to the Activity and Fragment class to support multi-window display. inMultiWindow()
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.
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.
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.
Subscribe to our newsletter and know all that’s happening at Cabot.
YOU WILL BE HEARING FROM US SOON!
We look forward to hearing from you!
YOU WILL BE HEARING FROM US SOON!