Questions regarding applying a Model-View-ViewModel in android application
Questions tagged [android-mvvm]
773 questions
9
votes
2 answers
How to request or remove the focus on edittext using data binding
I am learning mvvm structure and making an app using mvvm structure and data binding also.
Now, what I want to do is, I wanted to fetch a user from sharedpreference, If I am getting a user successfully then, I would set the name of usr to…

Riddhi Shah
- 3,092
- 5
- 36
- 56
8
votes
2 answers
What is right place to start a WorkManager in MVVM architecture Android?
I have a workmanager that every five hours picks up a word from the roomdb and Notification it
I do not know where is the righ place to put the work manager in the MVVM architecture.
Should I use in ViewModel or Repository?

Mahdi Zareei
- 134
- 9
8
votes
2 answers
MVVM with Retrofit - How to deal with a lot of LiveData in Repository?
I'm following this tutorial on using MVVM with Retrofit
https://medium.com/@ronkan26/viewmodel-using-retrofit-mvvm-architecture-f759a0291b49
where the user places MutableLiveData inside the Repository class:
public class MovieRepository {
…

DIRTY DAVE
- 2,523
- 2
- 20
- 83
8
votes
3 answers
Should you pass coroutineScope as function argument?
I am experimenting with coroutines and feel unsure about passing coroutineScope to plain Kotlin UseCase. Can such approach create memory leaks?
Suppose we are initialising our UseCase in VM and will try to pass viewModelScope:
class…

Viktor Vostrikov
- 1,322
- 3
- 19
- 36
8
votes
1 answer
Koin sharedViewModel with SavedStateHandle
I have single activity application and number of fragments. Some of these fragments are using my viewmodel, typically like this:
private val myViewModel: MyViewModel by sharedViewModel()
What if I want to have the model both shared and keep its…

ror
- 3,295
- 1
- 19
- 27
8
votes
1 answer
When to use executePendingBindings() and when its not required?
I am looking for a practical example for both the cases that what to use when? I have seen similar threads but they only tell this "when binding must be executed immediately" but there is no real time example for any case where you have to force the…

sak
- 1,230
- 18
- 37
8
votes
2 answers
LiveData Paged List size is always 0
I implemented Paging using android paging library. The ViewModel returns a LiveData> and I observe that in the fragment where I set the adapter and everything is working good, except that when I want to check the size of the list…

max
- 443
- 7
- 13
8
votes
1 answer
How to handle onClick or onTouch like events in ViewModel with data binding in MVVM Android
I have gone through many blogs related to MVVM model with Data Binding.
As data binding with ViewModel makes it easy to write junit test cases.
I want to know, how can I implement listener events like OnTouchListener, OnClickListener,…

Kavita Patil
- 1,784
- 1
- 17
- 30
8
votes
1 answer
Using SharedPreferences or File on MVVM
I am curious about the role of the repository in the MVVM architecture .If you decide to add repository to your project, will this repository be responsible only for data from database or network ? The question is about SharedPreferences or Files ,…

coroutineDispatcher
- 7,718
- 6
- 30
- 58
8
votes
1 answer
Questions about the responsbilities of each component in Android Architecture Components
I've been using MVP for a long time now and I'm starting to transfer to a hybrid state between MVP and MVVM
In detail my apps will go like this:
Each Activity has a 0 to x Fragments that represent its views
Each Fragment will request the Activity's…

Cruces
- 3,029
- 1
- 26
- 55
8
votes
2 answers
How to send data between activities using ViewModel
I used the same process for sending data between fragments and it works but now I'm not getting data in Receiver Activity. Even the Log message Tag is not showing as I click on submit button. I checked in Sender Activity Log message and it is…

Ayush Katuwal
- 139
- 1
- 2
- 11
8
votes
1 answer
Best approach to start an Activity from ViewModel in MVVM Architecture
I am following MMVM architecture in app, Everything was working fine untill I got a crash using following code to start an activity from ViewModel. Method is called from XML using databindings and passing view as parameter and getApplication() is…

Piyush Agarwal
- 25,608
- 8
- 98
- 111
7
votes
1 answer
Single live events in multiple fragments with Shared ViewModel
I have a shared viewmodel in multiple fragments.
class MainFragment {
private val sharedViewModel: HomeActivityViewModel by activityViewModels()
}
class MagazinesFragment {
private val sharedViewModel: HomeActivityViewModel by…

SpiralDev
- 7,011
- 5
- 28
- 42
7
votes
3 answers
Use the same instance of view model in multiple fragments using dagger2
I am using only dagger2 (not dagger-android) in my project. It's working fine to inject the ViewModel using multibinding. But there's one problem with that previously without dagger2 I was using the same instance of viewmodel used in activity in…

Deepak Kumar
- 677
- 1
- 8
- 22
7
votes
2 answers
How to use Dagger 2 to Inject ViewModel of same Fragments inside ViewPager
I am trying to add Dagger 2 to my project. I was able to inject ViewModels (AndroidX Architecture component) for my fragments.
I have a ViewPager which has 2 instances of the same fragment (Only a minor change for each tabs) and in each tab, I am…

hushed_voice
- 3,161
- 3
- 34
- 66