Questions tagged [android-mvvm]

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

773 questions
14
votes
1 answer

Is it Fine to use ViewModel without Live Data

I am using LiveData in AndroidViewModel class where i need to wait for the response, but there are some cases where i need to check some value from local shared preference, which won't block any thread. For these scenarios i am not using LiveData.…
dev90
  • 7,187
  • 15
  • 80
  • 153
14
votes
6 answers

Android Databinding onLongClick not working

I have a text view to which I need to create a listener for onLongClick. Right now for the respective viewmodel it has a function sendLogs() which deals with the logic for onClick. If I change onClick to onLongClick function never get call. Is there…
M P Mathugama
  • 1,418
  • 1
  • 20
  • 31
13
votes
1 answer

Saving activity's state with onSaveInstanceState() and ViewModel

I was left with some questions regarding ViewModels after reading this: https://developer.android.com/topic/libraries/architecture/saving-states It says here that you should use a combination of both a ViewModel for configuration changes (like…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
13
votes
3 answers

How to check permission is granted in ViewModel?

I need to ask permission for contacts and when application starts I'm asking,in ViewModel part I need to call method which requires permission. I need to check permission is granted by user or not and then call, but for checking permission I need…
I.S
  • 1,904
  • 2
  • 25
  • 48
12
votes
1 answer

Where to put business logic when working with mvvm

I am making a user login screen using MVVM design pattern but I am stuck when its come to implement the logic for phone number validation. I read out Rules to follow when working with mvvm (Rule no. 4) that View should not have any logic in it, Not…
Lokik Soni
  • 602
  • 1
  • 5
  • 25
11
votes
2 answers

LiveData observer is being triggered multiple times using Navigation Component

Scenario: I have two fragments named FirstFragment and UnitFragment. I go from FirstFragment to UnitFragment to select a unit to come back to FirstFragmet using navController.popBackStack(); and send unit data to FirstFragment which is observing…
11
votes
2 answers

How to use data from one ViewModel in another ViewModel

I have an AddressesViewModel which holds the user's favorite addresses and another SearchViewModel which holds searched addresses. when user searched an address I have to check whether this address is favorite or not by checking in the favorites…
Ofek Regev
  • 467
  • 4
  • 18
11
votes
2 answers

android LiveData Observable doesn't return data if calls are made quickly

Working on an app which requires sending multiple API calls to the same endpoint in one go. Eg - Directory browsing scenarios, need to get the directory structure by sending get calls for all folders in a current folder. The issue is, the response…
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
11
votes
1 answer

How to set click listener and pass edittext fields value to view model using data binding

Hi I am trying to use data binding and mvvm architecture in my android app. I want to add click listener using data binding in the layout and send the values of username and password edittext to the view model and it will execute the web service and…
N Sharma
  • 33,489
  • 95
  • 256
  • 444
10
votes
2 answers

Android Architecture Components(MVVM) - Ideal way to deal with remote and local data using repository pattern

I have browsed through a lot of sample code available for the new architecture components but I am still facing some issues in setting up my project. I need to fetch data from my remote service and save it to the room database. I want my view to…
10
votes
1 answer

what is the difference between presenter in mvp and view-model in mvvm

I need to clear some of my doubts regarding mvp and mvvm design pattern 1) In mvp and mvvm who updates the view .The presenter/view-model set the data to be displayed in the view or the view retrieve the data from presenter/view-model and …
user6250541
9
votes
2 answers

Android Permissions in MVVM at repository level or inside Activity?

I'm using MVVM clean architecture and need to get current position using fused location provider, so before getting the current position i need to check if user has given permission to access the location and the internet. I'm retrieving the…
pdcmb
  • 131
  • 1
  • 5
9
votes
2 answers

proper place to use location api in android mvvm architecture

I have a scenario, I want to show user current weather data for that I am getting his/her current lat/lng and reverse geocoding it to get the city name. Once I have the city name I will make a network call and show the weather data. Apart from this,…
sagar suri
  • 4,351
  • 12
  • 59
  • 122
9
votes
2 answers

Why is unit testing harder in MVC than in MVP and MVVM

I've been doing some research on pros and cons of MVC/MPV/MVVM and one common theme is that MVC is harder to unit test than MVP and MVVM but I don't fully understand why. From my current understanding, in MVC, the view is dependent on the model and…
user3826764
  • 198
  • 1
  • 9
9
votes
2 answers

Google SignInButton's onClick doesn't work using DataBinding

When I try to set the onClick method in my Google's SignInButton: android:onClick="@{() -> viewModel.onGoogleLoginClick()}" I always get this error: Found data binding errors. ****/ data binding error ****msg:Cannot find the proper callback class…
Óscar
  • 1,143
  • 1
  • 19
  • 38
1
2
3
51 52