Leanback Library For Android Smart TV Application Development

Posted By : Arun Kumar | 04-Feb-2020

In this blog post, we'll study how to easily enable a smart TV application supported by Android TV using the Leanback library. At the end of the blog, we can expect to have a UX compliant single APK for Android TV that aids in smart TV application development.


Overview of The Lean-back Concept

To make easy integration for developers android created the Leanback library. The core fragments you'll be working with are:


BrowseSupportFragment - For browse through a video player with a complete video library

PlaybackOverlayFragment - For getting the full control of video playback

DetailsFragment - To Display the details information of a particular video


All these fragments are using the Model View Presenter pattern. We'll bind our data model to the view using presenter class.


Browse Support Fragment

In this step, you'll learn about the framework for the video browse support fragment. The following concepts to take away in this step are:


a). Update the android manifest for Android TV

b). Extends our fragment with the Leanback Browse Support Fragment


Add these Lean-back dependencies to the build Gradle file. and synchronize these;


  implementation 'androidx.leanback:leanback:1.0.0'

  implementation 'androidx.appcompat:appcompat:1.1.0'


For an application that requires support for old versions of Android, we should make sure that the path of code utilizing libraries with a higher minimum SDK does not run on devices with version < minimum SDK (library).


Now, create a browsing activity.

In the Android Studio project, create a new project with package name com.android.example.leanback by right-clicking the folder and clicking New -> Package.

Name the new package lean back demo.


source: Google Codelabs


Creates a new Blank Activity name as Leanback Activity, and click on Finish;


source: Google Codelabs


If we want to use lean-back for the android smart TV then we should declare the launcher activity for Android TV. and add an intent filter to the LEANBACK ACTIVITY tag. that is android.intent.category.LEANBACK_LAUNCHER which told to Android TV to launch LeanbackActivity when the application is on the running state.


and also we should declare the lean back tag in the manifest;

For handling unsupported hardware features in the android smart TV

Some features are not available on smart TV, We need to explore their requirement. If We use any of the following features we'll need to add the android: required="false" to the manifest. In the following image we'll under the about it;


The Browse Support Fragment class in the android Leanback library which allows us to create a primary layout for browsing categories as well as rows of media items with a minimum amount of code.

                                                   Browse Support Fragment with combination of Row Fragment and Side Navigation Categories


Details Fragment

The Details Fragment includes classes for displaying additional information about the description, reviews, and media items and for taking action on that item, such as purchasing it or playing its content etc. We can see the example of details fragment in the following picture;

source: Medium


For every application, especially for smart TV application development, UI is one of the biggest differences between the Android smart TV application. We need to make UI suitable for smart TV usage. Because the user uses a remote control and cannot use the “touch screen” like mobile function with a smart TV. To achieve this requirement, the Leanback library plays a major role in android smart TV application and it has multiple widgets and features that are better for the developers as they can easily implement UI which satisfies these requirements and thus suitable for TV usage.

About Author

Author Image
Arun Kumar

He is very energetic, wonderful and enthusiastic, with amazing Brain!. He tries to achieve near perfection in his work, be it code quality or design of user interface. He is able to deliver his work before specified deadlines and norms.He is rising talent

Request for Proposal

Name is required

Comment is required

Sending message..