--ADVERTISEMENT--

Android 7.0 Nougat brings support for more than one application open and run at the same time. This is not the new concept because Samsung’s been doing it earlier, Microsoft and even Apple is doing it already. Now it comes on all Android devices running 7.0 and higher version. In this tutorial, you will learn to make your app working as split screen mode, picture in picture mode, and freeform screen mode.

Switch to multi screen mode; open an app on your device and long press the overview button, drag the app to one side of your screen to put the activity in multi-window mode. Multi-window mode is one of the awesome features that has blessed large android devices. It lets you to easily complete multiple tasks on same single screen dividing in to different parts. You can write something in notes app by watching YouTube video or news etc.

Related:
Android Drag Select RecyclerView Library
Facebook Integration in Android - Facebook Login
Adding a Share Action to Android Application

Android 7.0 Nougat: Split-Screen Mode, Picture-in-picture Mode and Freeform Mode



Android Multi Window Split Screen and Freedom Tutorial


Let’s start by creating new android project with Multi Window App Development app name and viralandroid.com as company domain. Select the minimum SDK to Android N.

First Activity User Interface


Open activity_main.xml layout file from res> layout and add a Button and a TextView inside ConstraintLayout. Your root layout is ConstraintLayout (android.support.constraint.ConstraintLayout). TextView contain default text Hello World! And Button contain onClick attribute and text Start.

First Activity User Interface

Main activity XML layout source code

res/layout/activity_main.xml

Second Activity User Interface


Add new activity XML layout by right clicking on the layout and enter the XML layout name for second activity; activity_second.xml. Second activity will be lunched when the user clicks on the button in first activity. In second activity of XML layout file we will add only a TextView inside LinearLayout. Following is the XML code of second activity.

res/layout/activity_second.xml



Java Code for MainActivity.java and SecondActivity.java File


Launch second activity from first activity when Start button is clicked. Here we add i.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |Intent.FLAG_ACTIVITY_MULTIPLE_TASK |Intent.FLAG_ACTIVITY_NEW_TASK); and Rect rt = new Rect(0, 0, 100, 100) ActivityOptions actoptions = ActivityOptions.makeBasic(); ActivityOptions bounds = actoptions.setLaunchBounds(rt); Following is the complete source code of main activity file.


src/MainActivity.java

And default java code of second activity is looks like below:

src/SecondActivity.java


AndroidManifest.xml File


Inside MainActivity of Android Manifest file add android:resizeableActivity="true" and define activity second below first activity which is looks like below:

AndroidManifest.xml

And finally build.gradle file looks like this:

Android Multi Window Split Screen and Freedom Tutorial

Now run app by clicking run button. Switch into multi window mode. To switch into multi window mode long press on the overview button and drag the app to one side of the screen, which looks like below screenshots.

Post a Comment

Powered by Blogger.