Android Jetpack: turn applications into rockets

    War War never changes. So, the war for a beautiful and working code goes on constantly. And for each complex task a weapon is born: someone makes it for themselves, and someone uses ready-made tools. Android development is no exception. At our conference AppsConf 2018, we will discuss how and what is the most interesting thing to use now, where you can get stuck and what interesting things are in the huge arsenal of development tools that Google has finally begun to put in order. The main topics of the reports can be viewed on our website, but for now we asked Denis Neklyudov and Alexander Smirnov to tell Google Developer Expert about the new Android Jetpack toolkit, which was introduced in May of this year.

    Alexander Smirnov, co-founder and CTO at PapaJobs, founder of the Android community of developers MOSDROID, host of the “Android in faces” video blog.
    Denis Neklyudov, the first GDE in Russia, works in Singapore at, the center’s host for the AndroidDev podcast, speaker at various conferences and author of several development courses.

    Android Jetpack was introduced in May of this year on Google I / O.
    What did you expect from that conference? Expectations were met?

    Alexander Smirnov : I was expecting a lot less than in the end. It seemed that developing a platform from a business point of view was not particularly necessary. In the mobile segment, Google achieved a confident victory in 87% of the market with positive trends, and the last few years have seen ML as their main focus. I was waiting for progress on Material Design, adding ML-tools for developers, release Constraint Layout 2.0. But we saw a huge step in restoring order and supporting developers. Suddenly pleased with the new items in the AJP and the beginning of the struggle for improved support. Hello, Android X.

    Denis Neklyudov: I adhered to the main rule of trips to the grocery conferences: do not wait for announcements, revolutionary changes, gifts - nothing but a meeting with old friends. Just to not break anything. But no, they presented Android X, the migration to which is not the most pleasant process in large projects. But there was a lot of positive. The most valuable thing in Google I / O is communication with the developers of the framework and colleagues in the workshop.

    What new items have already been put into practice?

    Denis Neklyudov: From AJP we tried only migration to Android X. I have a proven set of solutions in my project, there is no desire to hurry and implement new components. They simply supported Target SDK 28, checked on the recent release of Android Pie and calmed down. We are waiting for the promised improvements to be made available for testing. Jetpack now is various small libraries assembled in one place, which sometimes make the life of developers a little easier and more pleasant. Most new products are not yet ready for release versions of applications.

    Alexander Smirnov :
    From the presented novelties I tried everything, but in production we only updated the application to the new Material Design and applied Android KTX, which was pleasant for its simplicity and convenience. I like to fold a bunch of code in a few lines. The rest is thrown into the pipeline and proceed this year.

    Jetpack successfully completed the tasks, and you enjoy using it. But yes, some sections are still in alpha, so during the development phase small problems may come up. This is normal. I would not recommend hauling into production in alpha, but with the same Kotlin this did not stop me.

    For Android, the question of easy navigation has always been acute.
    Will anything change with AJP?

    Denis Neklyudov: In Android, navigation has always been powerful and diverse: Activity, Fragment, DeepLinks still need to process and monitor the arguments passed. You can easily get lost in a large map map. Google is just trying to solve this new Navigation, which is even built into Android Studio with its own screen hierarchy reactor.

    I use homemade solutions that meet the requirements and the overall architecture of the project. While in Navigation there are serious bugs and it is not ready for use in published applications.

    Alexander Smirnov: In Jetpack Google made a serious step forward: Navigation appeared, which will change the architecture of applications for the better. In large applications, navigation can become so complex that it’s unrealistic to remember all the transition options. And they still need to be programmed and tested. There were several alternatives that tried to solve this: Cicerone, Flow, Conductor. None of them is so functional.

    First of all, it is worth noting the Navigation Editor: it is convenient to build a graphical transition diagram with it, and it is pleasant to control it with the mouse. Implemented convenient handling DeepLinks with support for playing the entire transition tree. Navigation Component divides the work with DeepLinks into two cases: Explicit and Implicit. The first we can create ourselves through convenient DSL and call as PendingIntent through a specific action. The second is familiar to us DeepLinks, for example, from the browser. They are created and called in different ways, but are identically processed using the navigation graph and full stack building support to open the required section. Processing DeepLinks has never been so easy.

    Paging Library has been added to AJP. How does it change work with RecyclerView?

    Denis Neklyudov: RecyclerView has always had a drawback: you need to spend a lot of time on a solution that will perform page-by-page loading in both directions, and also with the ability to jump to different parts of this endless list. In the Paging Library, Google presented its solution to this problem.

    Alexander Smirnov: The library repeats the routine operation of most Android developers - working with lists. All of us, to speed up the display of large data sets, we break them into pages and work with them. With the help of the Paging Library, this work becomes easy, as we get the implementation out of the box. Additionally, the component can work on loading data from several sources and mix them. We also get an interesting idea with Placeholders, when at the moment of reloading data you can show beautiful plugs instead of eternal spinners. In addition, a kill-feature has been added to work with snapshots or unstable data - a component can understand itself what has been changed and which elements need to be thrown into the center of the list, and which - at the beginning.

    In essence, this component was created to work in conjunction with the RecyclerView, but the Paging Library consists of two main parts: the PagedList and the PagedListAdapter. Actually, with the help of PagedList, you can work with given chunks, download from several sources.

    One of the new products is Workmanager. How does he change his work with background tasks?

    Alexander Smirnov : It helps to systematically get away from all-powerful services to a convenient API in Jetpack: it allows you to add the need to fulfill the conditions of the environment to start a task, to set the order of execution of tasks and chains. You can transfer data to an executable task and get the result from it. It has three huge advantages: you do not need Google Play on your device, you can run tasks only if certain conditions are met, you can create chains of tasks.

    None of the past analogues was self-sufficient, so there was a library such as Android-Job from Evernote, which used all the analogues at once. After the appearance of the WorkManager, there is no need for them.

    Denis Neklyudov: Google got such a big wrapper over all existing solutions for working with background tasks. The fact that the deferred task just in Service will not succeed, the developers are faced with the release of Android Marshmallow and the arrival of Doze Mode. Now the application can not do whatever he pleases. And with each version of such restrictions more and more. Even with Lollipop, JobScheduler is available to us, which runs background tasks under certain conditions and with the consent of the system, but it has bugs on earlier versions and it is unclear how to work with it in Android versions, where it does not exist. For this, a wrapper was created as a GCM network manager and rewritten again as a Firebase Job Dispatcher. But even they turned out to be imperfect - this is how the modern replacement of WorkManager appeared,

    A new feature has been added to the AJP - Slices. What is interesting in it?

    Alexander Smirnov : First of all, Slices should be shown to your product and marketer. They allow the user to more often see your application and quickly use the necessary part of it: go directly to the desired section, switch the necessary feature. Slices also allow your application to participate among search results in Google Search, and will be able to be integrated into Google Assistant in the future.

    In Slices, you can display functions that are related to the type of your application and its capabilities. There are three groups: navigation, task execution, return to data. In general, users receive more simple and fast interaction from Slices, developers - more traffic and opportunities to return the user to the application.

    Denis Neklyudov: Admit it, you have long lacked the ability to get information in applications with interactive elements from applications directly from the search. Slices solve exactly this problem, allowing the application to declare the UI and actions with it, which will be built into third-party applications, including the search. I’m really looking forward to when the news on Google’s Smartphone Assistant is embedded from Feedly, pictures of the past from Timehop, my flights from App in the Air, the route to “Ya.Navigator”, etc.

    For application owners this is a great opportunity to increase the frequency of using their services, the user will also be more convenient to switch tracks in Spotify, without leaving the new racing simulator.

    And what are the limitations?

    Alexander Smirnov: Slices is still heavily trimmed with templates: a bunch of applications are embedded in others and the user needs to understand that the interaction mechanism will be different. For universality you always have to pay. If you recall Widgets, they were also very limited. Expansion of functionality, of course, will be, but I do not think that this is worth waiting for something big.

    Denis Neklyudov : I agree, now the Slices API is limited to some set of possible templates that can be embedded into a third-party application, but new versions will appear and new templates. The developers specifically banned custom interfaces in order to be able to control how the slices look in an embedded application and that they are all consistent.

    Google has added a KTX library to the AJP. What are your impressions of her?

    Alexander Smirnov : A great tool, this is exactly what was missing for a very long time. KTX is a set of extensions for more enjoyable use of the Android API in everyday tasks.

    I highly recommend switching all Android developers to it in order to increase productivity. It gives convenience, speed and good mood when working out. With KTX, you can even more slap the boilerplate and get neat, readable code.

    But you need to thoroughly examine the extensions that KTX provides and view the source code of these extensions in order to understand what is going on under the hood. And since there are no more pitfalls, you can safely take it into battle.

    Denis Neklyudov: AJP developers came to the right decision: the framework should be more friendly to Kotlin. Thus was born a project with a set of static functions that extends the syntax of the framework. Kotlin has many convenient language features, and just as extension-functions allow you to access the framework classes in a convenient manner. For example, view.isVisible goes as a short alternative for view.getVisibility () == View.Visible.

    There are a lot of different functions, better see for yourself . Of course, you can live without them, as, in fact, without Kotlin. But so nice.

    Google is increasingly promoting Kotlin. What do you think about it?
    What are his prospects?

    Alexander Smirnov: I treat Kotlin very positively and since January 2016 I have been using it as the main development language on Android. During this time, he participated in the migration of three companies from Java to Kotlin. Java, unfortunately, is developing rather slowly, and Kotlin for mobile development is a breath of fresh air.

    The moment when Kotlin becomes the main development language for Android is a matter of time. Android developers are already emerging, in which Kotlin is the first development language, and Java is something unfamiliar. We have a pleasant future with Kotlin, in any case, until Google decides to build a new OS, so to speak, an improved Android. But this is a question of a distant future, which is not the fact of what comes.

    Denis Neklyudov: I can’t say that Google is actively promoting Kotlin, rather, some projects related to the framework itself become friendly to Kotlin. This does not mean that in 2018, the Java developer for Android is some kind of renegade or a minority representative. But the fact that Kotlin is becoming more and more confident and becoming the default language for developers, and this is good news.

    When you hear about Flutter - a cross-platform framework for mobile applications from Google, Kotlin Native immediately echoes, which is compiled under both Android and iOS. Many are waiting for it to become the language for everything: Android, iOS, Web, Embeded ... Napoleon’s plans for JetBrains. We are watching, reporting bugs, beta-testing and getting pleasure from a pleasant language, to which we managed to migrate our projects with minimal pain.

    It's been more than three months since the release of the Android AJP. How did he show himself?

    Alexander Smirnov: With the help of AJP, Google planned to help Android developers create high-quality applications even faster and without a zoo of additional solutions. And as a bonus, even easier for newcomers to Android development. I think the task of Jetpack coped.

    It turned out a cool set that solves the problems of most developers. But we can say for sure in about 6–12 months, when we come to the release of most innovations. For the time being, this stops many on the way to start using AJP in production.

    Denis Neklyudov: Google did not make AJP from scratch, but connected a lot of useful developments that are not included in the framework itself and are packaged into applications by their developers. It is a good idea to combine them all under one fashionable, bright name. Developers are well aware that there is now a single resource where you can find an official solution to a multitude of problems. At least it is convenient.

    Of course, not everything that is included in this set is already ready for use in serious applications, something is still at the stages of active development and debugging. From the framework itself, the persistent feeling of a beta version, I will not put pressure on the patient and discuss the IDE. But we are accustomed to Android.

    Everyone will find something useful in this list of libraries and solutions. And for novice developers, this is definitely a mandatory resource for familiarization so that they do not step on a known rake, but first try more or less official ways of solving their problems.

    What are the prospects for the development of AJP? What may be new next year?

    Alexander SmirnovA: Now we have a lot of new developments, so first of all they need to be finalized and stabilized. Then I would expect a systematic development of each of the components and tools, perhaps a slight addition of something new. Jetpack was a step forward, so I expect systematic improvements from next year, but in a year it can be very interesting. What is definitely worth waiting for next year is a tighter and more convenient integration with Android Studio.

    Denis Neklyudov: AJP will be expanded with each new solved problem that was made publicly available. With each version of Android, the base Jetpack will develop in the form of AppCompat and Material Components. What will appear in the near future - it's hard to say, I'm waiting for Nitrogen, a package of utilities for testing applications on a large scale, to be added.

    Globally, Google is constantly expanding the capabilities of the browser, what can this lead to in the future?

    Denis NeklyudovA: I constantly repeat that you do not need to take some of the steps of Google as something global and centralized. If the Chrome team has enough resources for the development of AMP, PWA, and now also WebAssembly, this does not mean that there is a conspiracy to take and transfer all to the web by 202 ... year. Like the development of Flutter does not mean that we all will use this framework, and then Android will be completely doomed to die, because first ChromeOS, and then Fuchsia will capture all user devices. This summer, Jake Wharton spoke at Droidcon Berlin with the reporthow the line between a web and native applications is blurred. From the report it can be deduced that in the current situation it is necessary to maintain all platforms separately and try to reuse the code between them. However, if you believe that the Internet can be very high-speed, stable and cheap all over the world, then maybe web applications have a chance to dominate. But so far it is hard to believe.

    Alexander Smirnov: The transition from native applications to Progressive Web Apps is the dream of millions of web developers, product managers and a huge number of other people. By choosing a PWA application instead of a mobile, the company simplifies the development, use, update, and user engagement. PWA is a good solution for a large segment of simple mobile applications, and we will not be able to completely abandon native development very soon.

    Well, who cares to listen to news from the world of Android development live, to learn more interesting things about the latest insidious plans of Google Enclave, to talk with experts directly, we are waiting at our conference AppsConf 2018 .

    For those who prefer to study everything at home, we have a YouTube channel , where AppsConf videos will be posted (a few months after the conference).

    And announcements of all events and useful materials, including future conferences, announcements of the best reports, invitations to meetings, decoded reports and useful articles, we publish on our mailing list .

    Also popular now: