Unresolved reference: testing

According to official google documentation we should add our test helpers for Architecture Components (LiveData) in a such way: // Test helpers for LiveData testImplementation “android.arch.core:core-testing:1.1.0” And at least for me it just doesn’t work. (see the question above) How it should be actually: // Test helpers for LiveData androidTestImplementation “android.arch.core:core-testing:1.1.0” Now everything works just … Read more

how to use Architecture Components ViewModel inside RecyclerView Adapter?

I am using Room Persistence library. Below is my code for recyclerview adapter using MVVM. You can see CartViewModel and I have initialized it into the constructor. The constructor gets the context from the activity, and I have cast it into FragmentActivity. private CartViewModel cartViewModel; public CartListAdapter(Context context, List<CartModel> cartModels) { this.context = context; this.cartModels … Read more

Android Architecture Components: using ViewModel for RecyclerView items

Funny, but answer – This is correct way, should be accepted 🙂 You can make some code clean-up and remove GalleryItemViewModel from PostViewHolder, because you are creating hard reference and not using it. Then dirrectly in onBindViewHolder() use it like holder.binding.setViewModel(vm); This is a link with MVVM code example that can help you.

Android Jetpack Navigation with ViewPager and TabLayout

Experimented with different approaches to handle TabLayout with Jetpack Navigation. But hit issues like having a full history of switching between tabs multiple times etc. Browsing known Google Android Issues before raising a request for a demo, I found this existing issue. Its status is Closed marked as Intended Behavior with the following explanation: Navigation … Read more

Android Architecture Components: Using Enums

I can use enum values at Room with TypeConverters. There are some parts to change at your code: 1) You must declare your Entity’s fields public or they must have public getters/setters. Or you’ll get below error: yourField is not public in YourEntity; cannot be accessed from outside package 2) You don’t need the @Embedded … Read more

Services and ViewModels in Android MVVM – How do they interact?

After some toying with different structures, the Service has found it’s place in MVVM. What was throwing me off in this situation was thinking a Service shouldn’t be started from a ViewModel and the fact that two repositories were necessary: Room Database to store Timers and a Service to represent the state of ongoing timers … Read more

Multi-module Navigation with Architecture Components

This is already a year-long but the library now can support this exact use-case! As of 2.1.0-alpha03, we can navigation through deep link URIs. Instead of adding the features as implementation details to each other, we can leave them unaware between themselves and use deep link navigation. Feature 1 – Detail – build.gradle dependencies { … Read more

Backup Room database

This doesn’t answer the original question How can I properly re-open room db after I close it? However, if moving everything to the original database file is what you want to do, then you don’t have to close the database in the first place. You can instead force a checkpoint using the wal_checkpoint pragma. Query … Read more

Activity with multiple ViewModels

According to the open/closed principle, you should create three different ViewModels. The complexity isn’t increased that much, and you are gaining the ability to move one ViewModel (or just reuse it) with the corresponding RecyclerView to the another Activity very easily. Of course, sometimes breaking rules makes sense – for example if you know, there … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)