Questions tagged [android-architecture-components]

A new collection of libraries that help you design robust, testable, and maintainable Android apps. Start with classes for managing your UI component lifecycle and handling data persistence.

Architecture Components compromises of below components:

Handling lifecycles Create a UI that automatically responds to lifecycle events.

LiveData Build data objects that notify views when the underlying database changes.

ViewModel Store UI related data that isn't destroyed on app rotations.

Room Access your data with the power of SQLite and safety of in-app objects.

Data binding Useful to bind data directly through layouts xml file, so no findViewById()anymore.

Navigation Handles navigating between your app's destinations.

1709 questions
51
votes
5 answers

MediatorLiveData or switchMap transformation with multiple parameters

I am using Transformations.switchMap in my ViewModel so my LiveData collection, observed in my fragment, reacts on changes of code parameter. This works perfectly : public class MyViewModel extends AndroidViewModel { private final…
48
votes
9 answers

How to use shared element transitions in Navigation Controller

I would like to add a shared elements transition using the navigation architecture components, when navigating to an other fragment. But I have no idea how. Also in the documentations there is nothing about it. Can someone help me?
48
votes
5 answers

Android Room: Order By not working

I am using the new Android ORM Room. And I faced the following issue, queries that use ORDER BY with arguments don't work. If I want to use the field populated from a parameter for ORDER BY it does not work. It just doesn't sort…
Sirelon
  • 6,446
  • 5
  • 26
  • 30
47
votes
10 answers

How to implement a ViewPager with BottomNavigationView using new Navigation Architecture Component?

I have an application with a BottomNavigationView and ViewPager. How is it possible to implement it using new "Navigation Architecture Component?" What is the best practice? Thanks so much
MaksymDovbnia
  • 530
  • 1
  • 4
  • 11
47
votes
3 answers

MVVM pattern and startActivity

I recently decided to have a closer look at the new Android Architecture Components that Google released, especially using their ViewModel lifecycle-aware class to a MVVM architecture, and LiveData. As long as I'm dealing with a single Activity, or…
NSimon
  • 5,212
  • 2
  • 22
  • 36
46
votes
1 answer

How to create BottomSheetDialogFragment using Navigation Architecture Component?

I am using BottomSheetDialogFragment for displaying few custom setting's. Requirement: When i click on any tab in BottomSheetDialogFragment i replace the fragment and add it to backstack so that when user click's onBackPress or Up action it should…
46
votes
2 answers

LiveData. Cannot assign to ‘value’: the setter is protected/*protected and package*/ for synthetic extension

I'm trying to implement a DB Observer with LiveData as described in the android documentation. As long as I'm programming in Kotlin I'm adapting the functions (originally written in Java) to it. When trying to save the data I find this…
kike
  • 4,255
  • 5
  • 23
  • 41
45
votes
3 answers

How to get lifecycle.coroutineScope with new androidx.lifecycle:*:2.2.0-alpha01

On 7th May, 2019 androidx.lifecycle:*:2.2.0-alpha01 was released announcing: This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here. On documentation it's…
Rajarshi
  • 2,419
  • 3
  • 23
  • 36
44
votes
5 answers

vs as a view for a NavHost

When using androidx.fragment.app.FragmentContainerView as a navHost instead of a regular fragment app is not able to navigate to a destination after orientation change. I get a following error: java.lang.IllegalStateException: no current navigation…
Dmytro Karataiev
  • 1,214
  • 1
  • 14
  • 19
44
votes
3 answers

LiveData observing in Fragment

As of 2019, I'm trying to follow a best practice on where to start observing LiveData in Fragments and if I should pass this or viewLifecycleOwner as a parameter to the observe() method. According to this Google official documentation, I should…
43
votes
4 answers

How to pass object of type Parcelable to a Fragment using Navigation type safeargs plugin

I am rewriting my simple UI app to use Navigation architecture component, I need to pass a Pojo that implements Parcelable, have not seen any doc on how to do that. Any help would be appreciated.
42
votes
2 answers

Warning: warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.lifecycle.LifecycleProcessor' less than -source '1.8'

Trying to build a sample using Android Studio 3 Canary 5 with Architecture Components and Kotlin gives this warning. Can anyone tell me the reason? Thanks, Ove Edit #1: This is a sample made some time ago by Dan…
41
votes
1 answer

Android MVVM ViewModel and Repositories for each entity?

With the Android Architecture components and the MVVM pattern I have some question. Based on most examples around the web there are usually simple examples. Have an entity for Room @Entity public class User{ ... } Have a DAO …
Alin
  • 14,809
  • 40
  • 129
  • 218
40
votes
12 answers

ViewModel in Kotlin: Unresolved Reference

I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance: ViewModelProviders.of(this).get(CustomViewModel::class.java) According to the docs, I should be…
40
votes
7 answers

LiveData.getValue() returns null with Room

Java POJO Object public class Section { @ColumnInfo(name="section_id") public int mSectionId; @ColumnInfo(name="section_name") public String mSectionName; public int getSectionId() { return mSectionId; } …