Android Jetpack | Mobiloitte

Introduction to Android Jetpack

Android Jetpack is a collection of software tools, components, and guidance to make great Android apps. It helps you to build a good and high-quality app, boost your development, remove boilerplate code and deliver a robust app. All these new features emphasize you to follow best practices and simplify complex tasks in an easier way. so that the developer is focused on building a great app.

Jetpack distributed all component in four category

  • Foundation
  • Architecture
  • Behavior
  • UI

Architecture

The Architecture of Jetpack includes eight separate libraries and tools that help you architect your app and manage the data used by and showed in the app. Most of these libraries are already exists. However, there are three new libraries: WorkManager, Navigation, and Paging. Let’s begin with the newest one:

Navigation
Navigating between activities and/or fragments are far easier. Now, with the Navigation library and the navigation viewer built into Android Studio, one can visually design how screens are connected to one another. Many people have observed that this is similar to Storyboards in Apple’s Interface Builder for iOS app development.With the use of Navigation, you can visually connect one screen to another using “destinations”. You can create a navigation graph that will have an initial destination that can have actions to go to other destinations. The considerable thing about this is that you can define animations in the visual editor. The library can even handle deep linking into your app. Transferring data between destinations can be done in a safer and secure way with a new plugin called safeargs. One can define what arguments the Fragments in the navigation graph accept from within the navigation file itself.

Paging
Now you don’t have to deal with a large amount of related data. The Paging library will help you by providing ways to handle the paging of data in a RecyclerView. The Paging library uses various key classes: DataSource, PagedListAdapter, and PagedList. PagedList is a list that loads data inactively from a DataSource, enabling the app to load data in chunks or pages. PagedListAdapter is a custom RecyclerView. Adapter that handles pages with a DiffUtil callback.For the DataSource, you will use one of three different subclasses: ItemKeyedDataSource, PositionalDataSource, or PageKeyedDataSource.

Work Manager
Over the years, there have been various systems built into Android for dealing with background jobs or alarms. They vary in different versions of Android and you have to write a lot of code to handle the different versions of the OS.WorkManager solves this complexity and gives you one library for creating asynchronous, deferrable tasks and defining when they should run. One can define one-time jobs or repeating jobs.

Data Binding
This library has been around for a while. Data Binding allows you to bind your data to your layout in XML, so that, when you alter your data in running code, the views defined by the layout are automatically updated. Furthermore, when your UI changes, your data objects are updated.

Live Data
The Live Data uses the Observer pattern for data but manages it in a lifecycle-aware manner. You get the advantage of automatic UI updates when data changes without calling UI elements when the UI is not in the correct state.Live Data is the class that executes the observer pattern, holds that data, and notifies listeners when that data has changed.

Room
If you have ever struggled to work with the SQLite database in an Android app, you will appreciate what the Room library does for you. You create various simple classes that define your data and how to access them, and the Room library will do most of the rest. The only SQL code you have to write is for queries, which are generally pretty straightforward. And you get compile-time checks of your SQL code when using Room.

View Model
While the Room library holds your data in permanent storage, the ViewModel class permits you to hold onto data in device memory in a lifecycle-aware manner. One of the good features of a ViewModel is that it can survive the reconstruction of an Activity or Fragment over a configuration change such as a device rotation. With ViewModels you can load data in the background and use LiveData to notify listeners that the data is ready.

Foundation

The Foundation area of Jetpack includes core system components, Kotlin extensions, and Testing Libraries. This includes the AppCompat library, which you’ve probably been using for a while, and the new Kotlin KTX extension library for easier development in Kotlin.

Android KTX
Android KTX is the only new library in Foundation and is combined of Kotlin extensions designed to streamline the development of Android apps.

When using Kotlin
There are various KTX modules that are linked to other libraries in Jetpack. For example, if you are working with the Navigation library, then you could use:

  • android.arch.navigation:navigation-common-ktx
  • android.arch.navigation:navigation-fragment-ktx
  • android.arch.navigation:navigation-runtime-ktx
  • and android.arch.navigation:navigation-ui-ktx

Behavior

The Behavior of Jetpack consists of libraries that help you interact with your user through the UI, including using video or audio. It consists of many components such as media, permissions, downloading, notifications, sharing and the new Slices library.

Notifications
We have Android Notifications since the beginning but have changed over time. They have become more demonstrative and can contain buttons and images. Since Android 5.0 Lollipop, a notification called a heads-up can be displayed. You can even use notifications on Smart Android Wear and TV for controlling media.

Permissions
This part showcases how to use and request permissions. Since Android 6.0 Marshmallow, permissions are now required to be requested and given before certain functions of a device’s components can be accessed, such as contacts, location, photos, and camera information. You can declare permissions in the manifest.

Sharing
This modification explains how to share content and the ShareActionProvider class and how to use it. You can share and receive information from other apps. You can create a shared file, share action, and use ContentProviders for sharing data.

Media
This area of Jetpack consists of the MediaPlayer and AudioManager classes. One can play media, use the MediaPlayer, and control the device volume. Android supports several media formats. One can also use the ExoPlayer library, which Google uses for its own media players.

Download Manager
This service helps you download files in the background. Avoid connection problems, retrying and you can even reboot the system by using the DownloadManager service. Since the DownloadManager is a system service, you can just start a download and listen for a broadcast event in order to handle the finished download. You don’t need to worry about network issues or crashes.

Slices
The Slices library is the new modification and lets you create UI templates to share your data through the system in rich, flexible layouts. For instance, Google gave Google I/O was a weather app that can show more data depending on the space it has to show. Right now, it is only used by the Google Search App but should extend to the Google Assistant.

UI

Most of the UI libraries in Jetpack are built on existing code. They include animations, palettes, Emojis, Android Auto, Fragments, Layouts Wear and TV. The EmojiCompat library is the latest of the libraries and gives you up-to-date emojis and the fonts needed to use them.

Animation
This extension consists APIs for the different types of animations available on Android. The Jetpack site documentation contains the old as well as new ways to use animations. Vector graphics and vector animations are also included.It also has a physics-based animation system that includes spring and flying animations. You can configure transitions between activities as well as property and object animations.

Fragment
The Fragment support class has moved into this behavior of Jetpack. It includes the different kinds of fragments, for instance, ListFragment, DialogFragment, and PreferenceFragmentCompat. The main part of a Fragment is the lifecycle, and the Fragment class included in Jetpack is well-integrated with the Lifecycle class in Jetpack: Architecture.

Layout
A Layout determines the Views and ViewGroups in an app. In the Jetpack Layout documentation, One can learn how to declare layouts in XML. It also describes some of the common layouts, such as LinearLayout, RelativeLayout, and the newer ConstraintLayout. Besides, you can pick up tips on more specific features like making lists of items with RecyclerView, as well as the card layout CardView.

Palette
You can pick colors for themes and from images to make your UI’s match your images with Palette Library. Using the Palette.Builder class you can also build a palette and choose different colors. You can produce the following kind of colors: Light Vibrant, Vibrant, Dark Vibrant, Light Muted, Muted and Dark Muted.

Conclusion

Combined, there is quite a lot included in Google’s new Android Jetpack package. All of the libraries you love to work upon can be found there, as well as several new ones.
You were introduced to the four main parts of Jetpack in this article: Architecture, Foundation, UI and Behavior. Some of the new libraries, like the Navigation library will change the way you build your apps, making it simpler than ever. WorkManager resolves a long-standing problem of  reliably running jobs at different times on different OS versions. Paging will help you with larger data sets and let you use RecyclerViews and adapters with less code. The Android KTX library makes working in Kotlin even simpler than ever before and will continue to evolve. Slices are new as well and, as you discover more, you should be able to make available more of your data outside of your app.

Also Read : Kotlin Vs Java -Which is Better for Android App Development