📜 ⬆️ ⬇️

Top reports on Google I / O 2017: Architecture and more

Hello! My name is Mikhail Barannikov, I am an Android developer in e-Legion. Recently I returned from Google I / O and decided to share my impressions and links to interesting speeches. In total, the conference had 14 parallel tracks, which means a huge number of reports. The article is useful for those who plan to watch video reports on Android development, but do not know where to start.



Program


Each member of Google I / O immediately selects the events he wants to go to. They are divided into several types:


Reports are divided into several topics: Android, Firebase, cloud technologies, advertising in applications, Google Play, assistant, design, mobile web, machine learning & AI and others. Selecting reports by category is easy: you are developing mobile web applications or you are interested in such things as Flutter and React Native - go to the mobile web if you are interested in artificial intelligence and machine learning - on events related to them.
')
I put a filter on Android in the Google I / O application and selected the reports that interest me from the presented list, adding them to “My I / O”.

Most of all, I was interested in reports about the architecture and application optimization. There is no perfect architecture, so I wanted to see what the guys from Google would offer. And they suggested: they tried to solve problems that everyone was tired of for a long time. Namely: binding to the life cycle, saving queries / data when turning, pleasant work with the database. Also told how to reduce the size of apk and speed up the gradle assembly. Unfortunately, even being present at the I / O, it is not possible to see all the interesting reports live, because some of them run in parallel.

Below I will tell you more about some interesting reports.

Life cycle and turns


Lifecycle, LifecycleActivity, LifecycleFragment, LifecycleOwner, LifecycleObservable, LiveData have been added.

Using the above, the developer will be able to bind in the life cycle of the activation, fragment or the entire application. To do this, you need to implement the LifecycleObservable interface. Not going into much detail: having a Lifecycle object you can check the condition of the life cycle now, or subscribe to certain life cycle events using annotations. This allows you to write components that work in accordance with the life cycle, and get rid of a lot of code in onResume / onPause.

LiveData is an Observable that knows and works in accordance with the life cycle. This is very useful if you want to start downloading data when subscribers appear or stop downloading if there are no subscribers. After the download is complete, call setValue (), and all subscribers receive this data.

But we also want to save queries and data when turning. For this we are offered to use the ViewModel. In it, we can store our livedata. ViewModel is not destroyed when the screen rotates. We can get the ViewModel using ViewModelProviders.of (FragmentActivity) .get (MyViewModel.class). If the ViewModel is not created, then a new one is created; if it has already been created, we will return the old one. Since inside the ViewModel is LiveData, the rest of the code remains the same. We get LiveData and subscribe to them. It is important to note that when subscribing to LiveData, if there is already data there, we will immediately return it. In fact, it works like the well-known BehaviorSubject from RxJava, but within the framework of its life cycle.
Watch from 1:00. This video describes Lifecycle, LiveData and ViewModel in more detail.



Database


Room was introduced. It should save us from the boilerplate code, work with SQLite and provide compile-time verification. Room using annotations allows you to work with the database. Unfortunately, you have to write SQLite queries with your hands. But then all the power of SQLite to our services. When working with Room, you will need to create the Entity data classes, the Dao interface, and the Database class. We also have access to some shortcut annotations in order not to write with your hands very simple SQL queries: Insert, Delete, Update. Room can return LiveData, which gives us the opportunity to subscribe to database updates without loaders. How long have we been waiting for this. Well, the final touch - Room supports not only LiveData, but RxJava 2 Flowable.

Watch from the second minute. Here more about the new approach when working with databases. Additionally, they talked about migration.



If you have very little time, but you want to look at the architecture, you can use the video on YouTube, start watching from 6:30. The architecture itself is explained starting at 28:20. This video provides a brief overview of the architectural components.



It's nice that they hear us and offer tools to solve problems. Now there are many test projects using this architecture. Presented tools inspire hope. Whether they managed to solve the tasks and existing problems - time will tell. It is also worth noting that this is not an ideal architecture and everyone should only use it. It was said that if you have your architecture and it works well, then you can safely leave it. If you start a new project, you can try this approach.

My personal top reports besides architecture


Best Practices to Slim Down Your App Size
How to reduce the size of the apk file, which leads to fewer undo downloads. How to reduce the amount of space occupied by resources and classes. Useful in product development.

Speeding Up Your Android Gradle Builds
As in 10 steps to speed up the build. Watch is worth the first half to the 22nd minute. Or watch immediately 22 minutes, where there is a list of all the optimizations. One of the optimizations is the use of Instant Run. The last time I tried to use it a year ago and immediately turned it off forever. The video says that they fixed a lot of the bugs related to the work of Instant Run. Well, maybe it's worth giving him a second chance.

Fragment tricks
A bit of work with fragments. In general, nothing new was told. Just shows how to work with fragments, and talked about setReorderingAllowed (). Watch from the 7th minute.

Best Practices to Improve Sign-In, Payments, and Forms in Your Apps
Auto-complete forms in Android O and transfer application data between phones using the Account Transafer API. If the second is useful, then the first is still relevant only for Android O (waiting for the appearance in the support library). The explanation of the system is from 4:45, the example of use is from 7:50. Data transfer starts from the 13th minute.

Android Performance: An Overview
Detailed story about Systrace and its use. Useful for developers who want to make the application as fast as possible. Using Systrace you can find bottlenecks in the application for optimization, but it will take quite a lot of time.

Total


General impressions of the conference are positive. We were pleased with the organization, the presentations themselves and the opportunity to talk, ask questions and get answers to them. A little upset that there is no huge innovation in Android O. At the moment these are small changes aimed at more convenient work of both the user and the developer.

Plans to reconsider the video from the conference. Reports interesting in my opinion can be found here .

Source: https://habr.com/ru/post/329454/


All Articles