Questions tagged [android-mvvm]

Questions regarding applying a Model-View-ViewModel in android application

773 questions
4
votes
0 answers

ViewModel object with list and nested objects

I am working on a new Android project and am using the new Architecture components but could use some help in some scenarios, as I do not understand the best solution. I have an object such as below public class Team { String name; String…
Patrick Coyne
  • 61
  • 2
  • 6
4
votes
1 answer

ViewModel is recreated after rotation; if injected directly with dagger2

Possible duplicate of this I am exploring android injections api with dagger2. So, in my sample application I have injected ViewModel directly in the activity; have a look at following code snippets. class SampleApp : Application(),…
4
votes
1 answer

ObservableField value inside ViewModel does not update UI with data binding

ObservableField value inside ViewModel class value is changed using EditText in layout however value is not propagated to TextView tv_summary. This is the layout
Thracian
  • 43,021
  • 16
  • 133
  • 222
4
votes
1 answer

Best practices and patterns in ViewModel + Data Binding. Is ObservableField in ViewModel OK?

Looking through the samples I seen 2 approaches to MVVM using Android Architecture Components. First approach: ViewModel provides LiveData Activity subscribes to LiveData When observer called Activity is setting data to ViewModel…
4
votes
0 answers

RecyclerView with DataBinding-MVVM

I am using concept of Databinding-mvvm to implement such things. I have declared recyclerview into the my mainactivity. like
Dhiral Kaniya
  • 1,941
  • 1
  • 19
  • 32
4
votes
2 answers

Add fragment from ViewModel in MVVM architecture

I am using DataBinding and following MVVM architecture, now i am stuck on how to add new fragment from ViewModel as we need defined click event on ViewModel. Here is my MainViewModel class public class MainViewModel { private Context context; …
Ravi
  • 34,851
  • 21
  • 122
  • 183
3
votes
1 answer

multiple states for multiple network call in compose viewmodel

I'm fairly new to Jetpack Compose. Currently, I have a ViewModel making 1 network call. class PlatformViewModel @Inject constructor( private val getProductListUseCase: GetListUseCase ) : ViewModel() I had 3 states. sealed class PlatformState { …
3
votes
1 answer

Android. How to use pagination with clean architecture?

I'm writing application with MVVM and clean architecture. On one of the screens I need to implement RecyclerView with pagination. I am going to use the library Paging3. Android Developer recommends using PagingSource and RemoteMediator in repository…
3
votes
1 answer

Cannot be provided without an @provides-annotated method - Dagger/Hilt

I'm trying to use Dagger Hilt with Retrofit and Corroutines to make a simple API consumption project. However, whenever I try to run the App, "DataQuoteApi cannot be provided without an @Provides-annotated method." And honestly I don't know how to…
3
votes
3 answers

Where to transform a result of WebService, in Repository or ViewModel?

I have an application architectured by: View -> ViewModel -> Repository -> Datasource. My DataSource is consuming a webservice and then receiving a Soap object, which I want to transform to a custom Pojo object. So, by using RxJava I am calling the…
mantc_sdr
  • 451
  • 3
  • 17
3
votes
2 answers

Android: ViewModel with paging 3 flow is leaking

My problem is, that my shopViewModel which holds an instance of a paging-flow is somehow leaking. I've tried to solve this problem by converting the flow into a livedata, but that changed nothing. ViewModel class ShopViewModel @ViewModelInject…
Andrew
  • 4,264
  • 1
  • 21
  • 65
3
votes
1 answer

Android - Will memory leak occur if view model contains activity listener reference?

ViewModel has a reference to a listener defined in the activity. Now when the device orientation is changed, will memory leak occur? Code: public class MainVM extends ViewModel { private Listener listener; public void setListener(Listener…
3
votes
1 answer

I have a problem with Livedata observer called multiple time

This is my CartProductItemDao. @Dao public interface CartProductItemDao { @Query("select * from CartProductItem where product__category__id = :id") LiveData> getCartProductItemList(int id); @Query("select *…
3
votes
3 answers

How to pass data from activity or fragment to viewmodel?

I am creating a project in which i am using themoviedb api to fetch data. For this I am using MVVM architecture. From MovieListFragment , I want to pass category such as popular, top_rated to MovieViewModel for filtering the movies accordingly , but…
Rockers Devil
  • 31
  • 1
  • 1
  • 3
3
votes
2 answers

Android viewModel savedStateHandle

This is more of a conceptual question. Android recently introduced the concept of handling the state during process death inside viewModel rather than savedInstanceState which previously used to be in Activity or Fragment. My question is how do I…
Ma2340
  • 647
  • 2
  • 17
  • 34