Architecture components - introduction (Google I/O '17)

Android Developers · 136K views · 2017 · 38:27

Open on YouTube

Software architecture & designSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it as the official introduction when explaining what Android Architecture Components, ViewModel and LiveData are and why they exist.

Recommended by 3 people across 3 different months, 2017 to 2019.

What it is

A Google I/O 2017 session from the Android team introducing the Architecture Components libraries (Lifecycle, LiveData, ViewModel, Room). It covers common mobile app problems such as lifecycle complexity, memory leaks and unreliable networks, and presents a recommended layered app architecture. Yigit Boyar is among the presenters.

What people said

Recommends Levi Moreira · 2018-02 · Stack Overflow · on “What are Android Architecture Components,LiveData and ViewModel?”

In simple words: For a long time Google didn't give any indication to developers on how they should write (architecture wise) their apps. But last year they've released a set of libraries that guide developers on how to structure their code by structuring the app in clear layers and reinforcing good practices. That's what they call architecture components. LifeCycle, LiveData, ViewModel and Room are the main classes in these libraries. They go well with a MVVM architecture and if you apply them correctly (according to Google) your app will be easy to maintain and test. As for resources, you can check the Google I/O release talk [this video] and the documentation [LINK] . You can also find many on

Recommends Shababb Karim · 2018-12 · Stack Overflow · on “Android wait for volley to finish and update UI later”

The recommended solution right now is to use LiveData [LINK] . LiveData works on the Observer Pattern [LINK] , so you can have any number of observers to the updated data both in the Service and the Activity but they need to be under the same context. These are a bit advanced topics but a good way to decouple your UI with the data layer. You can go through these two links Google IO 2018 session on Livedata [this video] Medium Article on LiveData [LINK]

Recommends EpicPandaForce · 2019-03 · Stack Overflow · on “Get data from Search result(in a fragment) and update (other)fragments in the tab layout”

Easy, use a shared ViewModel obtained from the Activity as the ViewModelStoreOwner, so that you can put a LiveData of the "searched items" in that ViewModel, observe it in the fragments, and then when network call finishes and you update LiveData, all fragments will update automatically. See Google I/O 2017 introduction of Android Architecture Components [this video] for more info. Maybe also check this video [LINK] although it's a bit more bloated; and this codelabs: [LINK]

Cites Marian Paździoch · 2017-06 · Stack Overflow · on “Why using a LocationManager singleton in Android Activity is bad?”

In this talk (15:49) [this video] it's said sth which I do not understand. It's something like "when you use a LocationManager singleton in Activity it will cause memory leak". Can you explain how that LocationManager singleton causes a leak?

Cites Libathos · 2017-09 · Stack Overflow · on “How to respect Android Clean Architecture”

I've just read the Guide to App Architecture [LINK] . In this google demonstrates the basic guidelines for building robust android applications using the new Android Architecture Components. As shown in this year's Google I/O [this video] an app should have 4 layers: [LINK] Where the dependencies flow from top to bottom with higher layers only having knowledge of the components that are directly below them, eg. UI Controller only knows about ViewModel , ViewModel only know about Repository etc. So I watched the videos, completed the corresponding codelabs, then I studied the guide and after having a coarse understanding I began to code the use-case that was discussed in this guide. The object of

Cites azizbekian · 2018-01 · Stack Overflow · on “How ViewModel is persisted on configuration change”

Behind the scenes a retained fragment [LINK] is used. A retained fragment has its state retained across Activity re-creation (such as from a configuration change). See "Architecture Components Introduction" [this video] talk from Google IO 2017, where Yigit Boyar talks about ViewModel .

Cites EpicPandaForce · 2019-03 · Stack Overflow · on “In a fragment, how to find a view defined in the activity's layout?”

In my activity's layout, I have a view which I'd want to access from its attached fragment. No, you don't want to. How could I do it? getActivity().findViewById(R.id.blah) , but you shouldn't. But since my view is defined in the activity's layout, I can't do this. Technically you can, you just shouldn't. Could I use getActivity().findViewById? Yes, but you shouldn't. As for the correct answer, this is why they created Android Architecture Components: ViewModel / LiveData - so that you wouldn't be tempted to access views directly. You could modify the data/state shared via ViewModel in one place, and thanks to LiveData all observers would be updated with it. Therefore you never have to touch