Resizable Apps & Multi-Window Support in Android

Mar 30 2021 · Kotlin 1.4, Android 11, Android Studio 4

Part 1: Resizable Apps & Multi-Window Support in Android

05. Implement Multi-Window Mode Checks

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 04. Handle Multi-Window Lifecycle Next episode: 06. Launch Activities In Multi-Window Mode

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 05. Implement Multi-Window Mode Checks

If you tried resizing your app while in multi-window mode, you’d notice that the onMultiWindowModeChanged() function doesn’t trigger on every resize.

This is because this function notifies you only when the user enters, or leaves, multi-window mode. If you want consistent updates of your configuration, you have to override and handle your logic within the onConfigurationChanged() function instead.

The onConfigurationChanged() function, however, gives you updates whenever there is any change in the current configuration. Like before, this impacts the screen size, density, orientation, layout, color and much much more.

It’s best to use this function, in pair with the manifest flags you’ve added to your app, to react to any change within the app. Let’s see how to do that!

Open the NotesActivity.kt file and override the following function:

  override fun onConfigurationChanged(newConfig: Configuration) {
    super.onConfigurationChanged(newConfig)

    val newHeight = newConfig.screenHeightDp


  }

As mentioned, this function will trigger every time you resize the screen, change the language, density, scaling, colors or anything else in your config. However, we’ll use it to read the screen height after the config change.

You do so by using the newConfig parameter and its screenHeightDp property.

Now that you’ve read the screen height, you can change if your notes show up horizonally or vertically, based on the screen size. Do that the following way:

    if (isInMultiWindowMode && newHeight < 270) {
      binding.notes.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
    } else {
      binding.notes.layoutManager = LinearLayoutManager(this)
    }

Awesome! If you’re in the split-screen mode and the screen size is less than 270dp, which is a bit more than a quarter of the screen, you’ll switch to horizontal orientation of the list. Notice the isInMultiWindowMode property. It’s a convenience function that lets you check if the screen is in multi-window or not.

You could also pass in a different layout type for the notes, change if the add button shows up as a Floating Action Button or a menu button, and much more.

This should be a good example of how easy it is to react to changes in the config, and update your UI accordingly. Now build & run the app and try to resize the app in split screen.

Awesome! You can see how cool it is to react to multi window mode and how you can utilize multi-window checks to change your app to help the user run your app in split-screen.