Passing argument(s) to a nested Navigation architecture component graph

Global actions might be a way but I didn’t get that working as I wanted once I extracted the nested graph to its own .xml. But it turned out to be embarrassing simple – just add the arguments manually in code, to your action. An example related to the question would be: Save the nested … Read more

Room attempt to re-open an already closed database

It’s because you are trying to modify the schema of the existing database without giving it any migration information. So basically it attempts to write the new database schema to the existing DB which doesn’t work. There are two ways around this. If you are in your development environment what you can do is fallback … Read more

Android Persistence room: “Cannot figure out how to read this field from a cursor”

Document is really confusing. Try with just below classes: 1) User Entity: @Entity public class User { @PrimaryKey public int id; // User id } 2) Pet Entity: @Entity public class Pet { @PrimaryKey public int id; // Pet id public int userId; // User id public String name; } 3) UserWithPets POJO: // Note: … Read more

LiveData.getValue() returns null with Room

On the next line I am checking sections.getValue() which is always giving me null although I have data in the DataBase and later I am getting the value in the onChanged() method. This is normal behavior, because queries that return LiveData, are working asynchronously. The value is null at that moment. So calling this method … Read more

ViewModel in Kotlin: Unresolved Reference

Include the following as a dependency: implementation “android.arch.lifecycle:extensions:1.1.1” The equivalent AndroidX dependency is: “androidx.lifecycle:lifecycle-extensions:VERSION” in where VERSION can be replaced for Current Stable, Beta or Alpha values given in this official link This dependency is for both ViewModel and LiveData and thus would not require you to give separate dependencies for the same either; i.e. … Read more

Android MVVM ViewModel and Repositories for each entity?

1 You should have contextual DAOs, let’s say an UserDao which should contains the queries related to the users, if you have posts in your app, you should have a PostDao for everything related to posts. 2 Same logic for repositories, remember the Single Responsibility Principle for classes, sticking to that principle you should have … Read more

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

There is a Java 8 annotation processor now arch components are stable so replace: “android.arch.lifecycle:compiler:${rootProject.archLifecycleVersion}” with “android.arch.lifecycle:common-java8:1.0.0”

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

Since safe-args-gradle-plugin:1.0.0-alpha03 you can use Parcelable objects by using their fully qualified class name: <argument android:name=”item” app:argType=”com.example.app.model.Item”/> Parcelable arguments are now supported, using a fully qualified class name for app:type. The only default value supported is “@null” (https://issuetracker.google.com/issues/79563966) Source: https://developer.android.com/jetpack/docs/release-notes To support nullability one has to use android:defaultValue=”@null” with app:nullable=”true”.

LiveData observing in Fragment

If observing from an Activity you can observe on onCreate() and use this for the LifecycleOwner as stated here: If you have a lifecycle-aware component that is hooked up to the lifecycle of your activity it will receive the ON_CREATE event. The method annotated with @OnLifecycleEvent will be called so your lifecycle-aware component can perform … Read more

vs as a view for a NavHost

The no current navigation node error occurs when there’s no graph set and you attempt to call navigate(). If it only occurs when you’re using FragmentContainerView and after a configuration change, then this would be related to this bug, which is fixed and scheduled for release with Navigation 2.2.0-rc03. To work around this issue, you … Read more