Category: Blog, Android, Development

Multi-Window Simple Examples: Part 1 – Screen changes

Multi-Window Simple Examples: Part 1 – Screen changes

Introduction

As far as you know, from Android Nougat we will be able to run two different applications simultaneously. This functionality is called Multi-Window (or split-screen) mode. Don’t worry, I won’t rewrite the documentation, but of course I strongly encourage you to read it: Multi-Window Support. All the theory that you need is there.

What I’d like to present today are three very simple examples of what we can do and what we should care about during split-screen mode:

  1. Screen changes.
  2. Drag and drop.
  3. Launching another application.

This article simply explains how we can handle our application’s layouts when an app user changes the screen size.

Oh… I’ve almost forgotten. All examples take place in Pokémon world! And what’s more, in Part 2 of this article you will be able to catch Pokémon with another app!

To get Pokémon images I used Pokéapi.

multi_window_catch

Choose configuration changes events

First of all in AndroidManifest.xml file we should specify “configuration changes that the activity will handle itself” in android:configChanges attribute.

Note that in each of the named events (screenSize, orientation and so on) activity will not restart. In <layout> tag you can specify for example min. and default width and height of this activity.

Now we have to implement Activity.onConfigurationChanged() method.

All that I’m doing during the screen changes is checking if the orientation of layout is still portrait or was changed to landscape. Android framework does all the calculation, so if you change screen height in a way that width will be larger, you will receive Configuration.ORIENTATION_LANDSCAPE value in the new configuration. I created list item layouts for portrait and landscape orientation and as you can see I’m changing orientation also in RecyclerView.

And if I don’t want my application to run in split-screen mode?

Fortunately, there is a special tag for it – android:resizeableActivity.

For applications with targetSdkVersion version lower than N the default value is false, otherwise, it is true. Remember, it’s very important!

Summary

Screen changes during Multi-Window mode are almost the same that we have before N. There is nothing new about attribute android:configChanges or method Activity.onConfigurationChanged(). It is simple to support screen changes in a basic way and we should consider split-screen mode in our app designs.

Part 2 – Drag and drop >>