Last week was the Google I/O conference where experts presented the latest things developed by Google. While most of us waited with bated breath for new consumer products and services, the Google I/O’s benefits were directed to the Developers Community. With so many new things on the horizon for Android, it’s a bit hard to keep up with everything. In this article, I will cover the most massive change that has an impact on us as developers: Android Jetpack.
What is Jetpack?
Android Jetpack is a set of components, tools, and guidance to help us speed up the development process. Jetpack is a major update to how developers write applications for Android and represent the next generation of the Android Support Library.
Jetpack combines the existing Android support libraries and components and wraps them into a new set of components (including a couple of new ones) for managing things like background tasks, navigation, paging, and life-cycle management, as well as UI features like emoji and layout controls for various platforms like Android Wear, Auto and TV, as well as some more foundation features like AppCompact and Test.
The Android Jetpack components bring together the existing Support Library and Architecture Components and splits them into four categories:
An important note is that developers can choose whether they want to use Jetpack. Ahead of this announcement Google’s product management director for Android, told that the company will continue to release all updates in both the support libraries and Jetpack.
Android Jetpack comes with five new components:
- WorkManager alpha release
- Navigation alpha release
- Paging stable release
- Slices alpha release
- Android KTX (Kotlin Extensions) alpha release
WorkManager is a library used to enqueue work that is guaranteed to execute after its constraints are met. This library offers observation of work status and the ability to create chains of workers. Here we have two supported types of work supported by WorkManager: OnTimeWorkRequest and PeriodicWorkRequest.
An WorkerRequest can accept constraints, inputs and backoff criteria. They can be tagged with human-readable Strings and chains of work can be given an uniq name. By default a WorkManager runs its operations on a background thread.
Here is a sample where you can see how to enqueue, cancel and chain requests using WorkManager.
The Navigation API simplifies the implementation of navigation in our apps. This API can help us manage easier the navigation back stack and reduce the boilerplate of our apps. Start using this API will simplify our navigation and this means that we don’t need that Fragment transaction anymore. Deeplinking can be implemented easier. The most important feature offered by Navigation API is the Navigation Editor from Android Studio 3.2(Canary build). In this editor you can modify your navigation graph as you want.
You can find a sample of navigation below. This sample is made using three fragments and one activity. Here you can see the navigation flow and the deeplinking implementation.
The Paging component, when combined with RecyclerView, allows you to add fast, infinite scrolling to your app. The idea is that the component simplifies managing data in pages, ie. pulling chunks of data in succession as quickly as possible and returning results for the user to view.
Advantages using Paging API:
- Data requests consume less network bandwidth and fewer system resources.
- Even during data updates and refreshes, the app continues to respond quickly to user input.
You can check the code below to see how this library works.
The Slices component will simplify the process of implementing the Slices API introduced with Android P. It’s an API that lets you surface your app’s UI inside of the Google App as a search result. Below you can see a sample of Slices in Google search results.
These search results are interactive. Slices will start appearing soon for users, but you can start develop and build them today.
Some advantages using Slices API:
In the below sample code you can see how to create a Slice and how can you customize it.
Android KTX is a set of Kotlin extensions that is part of Android Jetpack. This extensions optimizes Android platform APIs for Kotlin use. The scope of Android KTX is to make Android development with Kotlin more concise and pleasant. Android KTX does not add any new features to the existing Android APIs. By using this extensions you will soon realize that you need to write less code for the same functionality.
Below you can find some samples with and without using Android KTX.
The Jetpack components should simplify our app development and help us reduce the boilerplate of the app. And because they are backward-compatible we can bring them on older devices without problems. Using this APIs we can create better apps easier.
Be aware that Jetpack components are in alfa release and they can change.
Featured Article here – https://medium.com/@vladioan3/android-jetpack-c1c3012c1f44
Latest posts by Vlad
- Android Jetpack - May 26, 2018