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
309
votes
10 answers

What is AndroidX?

I am reading about a room library of Android. I see they changed package android to androidx. I did not understand that. Can someone explain, please? implementation "androidx.room:room-runtime:$room_version" annotationProcessor…
285
votes
21 answers

How to clear navigation Stack after navigating to another fragment in Android

I am using The new Navigation Architecture Component in android and I am stuck in clearing the navigation stack after moving to a new fragment. Example: I am in the loginFragment and I want this fragment to be cleared from the stack when I…
272
votes
9 answers

Room persistance library. Delete all

How can I delete all entries on specific table using Room Persistence Library? I need to drop table, but I cannot to find any information how to do this. Only when database is migrating or to load all entries and delete them :)
Sirelon
  • 6,446
  • 5
  • 26
  • 30
252
votes
4 answers

AndroidViewModel vs ViewModel

With the introduction of the Android Architecture Components library, several new classes were introduced, including AndroidViewModel and ViewModel. However, I'm having trouble figuring out the difference between these two classes. The documentation…
244
votes
31 answers

ViewModelProviders is deprecated in 1.1.0

Looking at the Google docs for ViewModel, they show the below sample code on how to get a ViewModel: val model = ViewModelProviders.of(this).get(MyViewModel::class.java) When using the latest dependency android.arch.lifecycle:extensions:1.1.1 there…
229
votes
11 answers

When to use RxJava in Android and when to use LiveData from Android Architectural Components?

I am not getting the reason to use RxJava in Android and LiveData from Android Architectural Components.It would be really helpful if the usecases and differences between the both are explained along with sample example in the form of code which…
166
votes
21 answers

IllegalStateException: Link does not have a NavController set

I'm using Android Navigation Component for Navigation. I have a LoginFragment which has a button to transition to SignUpFragment. On clicking the button I'm getting this error. java.lang.IllegalStateException: View…
148
votes
35 answers

Cannot create an instance of class ViewModel

I am trying to write a sample app using Android architecture components and but even after trying for days I could not get it to work. It gives me the above exception. Lifecycle owner:- public class MainActivity extends LifecycleActivity { …
Parag Kadam
  • 3,620
  • 5
  • 25
  • 51
139
votes
14 answers

Cannot resolve symbol ViewModelProviders on AppCompatActivity

Hey I'm trying to get my ViewModel working, but no luck so far. Android Studio shows error Cannot resolve symbol 'ViewModelProviders'. Every other question I found on this topic was correcting extends Activity to extends AppCompatActivity, but I…
Sheler
  • 3,969
  • 3
  • 12
  • 21
138
votes
14 answers

Android Room Persistence Library: Upsert

Android's Room persistence library graciously includes the @Insert and @Update annotations that work for objects or collections. I however have a use case (push notifications containing a model) that would require an UPSERT as the data may or may…
Tunji_D
  • 3,677
  • 3
  • 27
  • 35
127
votes
8 answers

Observing LiveData from ViewModel

I have a separate class in which I handle data fetching (specifically Firebase) and I usually return LiveData objects from it and update them asynchronously. Now I want to have the returned data stored in a ViewModel, but the problem is that in…
115
votes
9 answers

How to get a result from fragment using Navigation Architecture Component?

Let's say that we have two fragments: MainFragment and SelectionFragment. The second one is build for selecting some object, e.g. an integer. There are different approaches in receiving result from this second fragment like callbacks, buses etc.…
114
votes
5 answers

How to update LiveData of a ViewModel from background service and Update UI

Recently I am exploring Android Architecture, that has been introduced recently by google. From the Documentation I have found this: public class MyViewModel extends ViewModel { private MutableLiveData> users; public…
113
votes
6 answers

Android Room: Insert relation entities using Room

I've added one to many relationship in Room using Relation. I referred to this post to write the following code for relation in Room. The post tells how to read the values from the database but storing the entities into the database resulted in…
Akshay Chordiya
  • 4,761
  • 3
  • 40
  • 52
111
votes
31 answers

Room "Not sure how to convert a Cursor to this method's return type": which method?

Error:Not sure how to convert a Cursor to this method's return type Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details. Using Room I'm getting this error and I'd like to…
1
2 3
99 100