What is Jetpack
In this article we will see what parts and features Jetpack that Google recently developed for Android applications include. Jetpack came at the Google IO 2018 event and got poplar by the Android developer community and is evolving day by day. To understand what a jetpack is, join us to get acquainted with the jet pack.
What is Jetpack?
Quite simply, Jetpack is a new way to build Android apps but simpler, hassle-free, testable and scalable. One of the problems that Android developers always faced was the complex structure of the Android Support Library. This library was originally as a way to adapt old versions of Android to new features. For example, the material design language in Lollipop version, which could not be in lower versions, but the Support Library allowed the programmer to use the material design in pre-Lollipop versions as well. But for example, one of the problems with the Support Library structure was its strange naming. For example Support Library v13, Support Library v7, Support Library v4 !!! The developer should have known that, for example, RecyclerView is in Support Library v7 and Fragment is in Support Library v4 !!! Well, this strange naming because of the complex structure made many programmers discouraged from continuing.
Another problem with Android was that due to the diversity of Android phones, both in terms of operating system and features. Developers faced with a big challenge to work safely and correctly on all phones. For example, you specified an animation to display your activity, but it worked completely differently on each phone.Another reason was that to integrate and reduce the complexity of the issue.
The Jetpack suite is in four parts: Architecture, User Interface (UI), Behavior, and Foundation.
In this article, we will talk about its most important part.
Architecture
One of the most important issues with programming is scalability, code readability, and testability. This section focuses on these issues, and by using the Android Architecture Component, you can achieve the properties that a quality software needs. The easy-to-implement Google MVVM architecture that the Android Architecture Component helps you implement. In short, MVVM divides the software into 3 layers. View, ViewModel, Model. The model layer is responsible for providing information, for example, getting information from the server or database, the View layer is only responsible for displaying information, and ViewModel is the interface between the Model layer and View.
ViewModel
The ViewModel function is the connection between the View layer (for example, your Fragment) and the Model layer (for example, your database). Suppose you want to get a list of notes from the database. In this case, you should not send the request directly from the Fragment to the database. Instead, you notify ViewModel of any events that occur to your fragment. ViewModel decides when to retrieve the information from the database. For example, when the onStart fragment method , requests a list of notes from the database, and you report the result to Fragment. But how to inform the information to the Fragment. The answer to this question is LiveData.
LiveData
LiveData is simply a data holder. The data packets that are between View and ViewModel can be of LiveData type. But what is the advantage? We will see later. In Android, the View layer, whether it is Fragment or Activity, has its own life cycle. This life cycle is very important because requesting and receiving information from the Model is completely dependent on the View life cycle. One of the advantages of being so-called Lifecycle Aware is that. That means you don’t have to worry about the View Lifecycle, LiveData manages it intelligently.
WorkManager
This tool is for scheduling time-consuming tasks. For example, with WorkManager you can specify that database information go with the server every 12 hours. One of the big problems with Android was the lack of an integrated and accurate system for scheduling specific tasks. There were various tools such as Alarm Service or Job scheduler, but for example Alarm Service was not accurate and only worked until version 19 of Android, and on the other hand Job Scheduler did not work on lower versions. But with Work Manager, there is no such concern anymore and it is guaranteed that if your work conditions are met, your work will be done on time. One of the cool things about WorkManager is that you can specify, for example, that every 12 hours the user is connected to the Internet but does not work with their phone. Well, this can be helpful in many cases, such as backing up photos taken and sending them to the server.
Paging
In many applications, you have noticed that for example, when they want to display the list of news, 20 news is the first, and when the user reaches the end of the list, the next 20 news is, because of the increased execution speed of orders, saving RAM and volume Is user data. This method is Lazy Loading or Infinite Scroll. From now on, you can use the Paging library to implement this scenario. The most important advantage of using Paging is the simplicity and support of RecyclerView.
Navigation
The Navigation Component is for connecting and controlling the Navigation application between fragments. For example, with this tool you can visually connect fragments and determine where to go from each fragment and even specify the arguments that each fragment needs.
In 2018, Google unveiled a new concept called SingleActivity and officially introduced it as a viable alternative to past methods such as multi-activity applications. However, before Google, Instagram used this concept, and in fact, the Instagram application has been SingleActivity for many years. But what does the SingleActivity app mean? This means that the application must have only one activity and all pages must be implemented with a fragment and these fragments must be loaded into the activity. But the advantage of this method and the reason for choosing it is a complete article to explain.
Conclusion
In my opinion, Jetpack is one of the biggest developments that Android programming has seen so far, and this move by Google can be considered a revolution in the Android application development industry. One of the most important features of Jetpack is that its components can interact well and work properly separately. For this reason, the word Component is used in it.