Jetpack for the post

background

1. The reason and value of Jetpack

As any developer familiar with Jetpack knows, Jetpack is a set of components that Google has created to address some of the pain points we encounter in Android development on a daily basis. Such as:

  1. Lifecycle components have been introduced to address data loss or crashes caused by Activity destruction reconstruction due to configuration changes such as screen rotation.

  2. Hilt was introduced to address the high technical threshold for using the dependency injection Dagger framework.

  3. To solve the problem of background task management, WorkManager was introduced.

  4. In order to solve the problem of convenience and threshold of SQLite database use, ORM framework Room was introduced to replace GreenDao.

  5. To solve the problem of navigating between fragments, Navigation was introduced.

  6. In order to solve the synchronization problem between UI update and data source in traditional MVC and MVP mode, the MVVM architecture mode of Databinding+Viewmodel+Livedata is introduced, which can easily achieve bidirectional binding and dynamic update.

  7. Kotlin coroutines are used with architectural components to further simplify the handling of our asynchronous tasks.

Jetpack’s emergence has two main implications:

  1. Simplify the life of Android developers, making it easier and cheaper for developers to build apps.
  2. There are recommended, standardized practices that make it easy to build quality applications.

Sunflower, a Demo application combining these architectural components, was released to introduce and promote Jetpack, and the official technical documentation for Jetpack is now complete. For example, the official recommended application architecture is shown below:

2. Is there anything else we need to do?

However, one interesting thing is that “usually official things cannot be well met in actual engineering practice with some specific needs”.

In order to solve these pain points, some developers will make some good wheels and open source, and Then Google will slowly absorb some good design, incorporate it into its own system, and come out with an official solution. This is not unusual, and is a common occurrence in software development. Okhttp, ButterKnife, GreenDao, Dagger all come from this way, and Google is constantly iterating and optimizing.

Jetpack is the same this time. Recently, I met some problems and doubts when I used Room and WorkManager in the project. It is also the direct result of this article and this activity.

3. Jetpack and I bonded

I started to know Jetpack and Kotlin quite early. A few years ago, I also attended several offline technical forums in Shenzhen to officially promote Jetpack and Kotlin. I was lucky to meet Hadi Hariri, the technical evangelist of Kotlin language, and had a brief communication with him. However, there has been no deep research, but more understanding and attention to its evolution.

For various historical reasons, our project was not written in Kotlin until late last year. Technical friends all know that there is a big difference in the depth of understanding between understanding theories and actually using them in projects.

Recently, I started a new project that was built entirely with standard MVVM, Kotlin, Jetpack, and I really got some good exercise and some thinking and deeper exploration.

4. The problem I’m having right now

    1. The problems I encountered in using Room

However, Room also has a lot of advanced design. For example, it can’t execute operations on the main thread, and when the main thread executes operations, it crashes. And if you write an SQL statement incorrectly, you can get an error at compile time. Using Room is much more efficient and requires much less code than using SQLite directly.

  • 2) Some doubts and problems I encountered when using WorkManager and reading documents on the official website

What do we want to do?

Obviously, Google’s official solution is not omnipotent. It may collect some pain points from various channels and then launch solutions, but it cannot cover all of them. It also needs to be iterated and optimized. In engineering practice, there may be some pain points that have not been well satisfied in the face of complex demand scenarios.

Perhaps they have not thought of or encountered scenarios, such as the scale of Internet of our country is larger, there are several big super APP user groups, the scene and technical challenges facing is perhaps now other countries are not met, the precipitate in the process of technical solution may be of guiding value.

For example, we precipitated the plug-in technology in the battle of wits with The Android system. This atmosphere is better than that of foreign countries, and it is also the product driven by some demand scenes. With the development of China’s software industry today, we can now communicate on an equal footing in some areas and export some technologies.

Based on the above reasons, we mainly want to discuss:

  1. Best practices for the Jetpack component, what its pros and cons are, what scenarios to use it in and what scenarios not to use it in. (Solve problems in use)

  2. Explore the principles of Jetpack and the gap between theory and engineering practice, and see if there are areas where the design is not friendly enough, or does not meet the needs of the scenario well, and can be optimized (solve the optimization problem).

Through the above exploration, we want to precipitate some more practical best practices.

In addition, learning technology alone is boring, inefficient and limited. It is also a blessing to find a group of like-minded people to study together. We can learn from each other and complement each other’s strengths.

It would be nice if karma helped more people with similar problems.

Finally, Android developers who are interested in Jetpack and meet the recruitment criteria are welcome to contact me. (Please specify: Jetpack)