Questions regarding applying a Model-View-ViewModel in android application
Questions tagged [android-mvvm]
773 questions
0
votes
1 answer
Handling error flow in single activity MVVM architecture: observers isn't triggered
I'm using MVVM in single activity application. As possible solution for error flow I decided to use activity as aggregation point for error representation(I considered that activity in this case is the most suitable place for this because it is…

Autumn_Cat
- 790
- 1
- 14
- 28
0
votes
2 answers
Android MVVM retrofit2 model not updating
Trying to call my API using retrofit and update the model. It initializes correctly and is able to pull the data but when I trigger it manually by pressing the update button the onChange QuestionResponse model is null. It seems almost like a race…

Ubarjohade
- 471
- 6
- 21
0
votes
1 answer
How to use MVVM with any fragment?
I have a TabLayout on a activity and when user clicks on any tab then a fragment is loaded. One of those fragments contains a NavigationView running inside a DrawerLayout. Now the problem is I have to implement MVVM for the whole app and so for the…

sak
- 1,230
- 18
- 37
0
votes
4 answers
Android remove Activity observer from Fragment
I have MVVM single Activity Application with task running every x min.
In Activity I'm observing result of that task. Everything works fine.
After navigation to certain Fragment I'd like to stop observing it in Activity and after navigation to…

solaza
- 1,251
- 1
- 17
- 30
0
votes
1 answer
Display icons along with text in TabLayout while using DataBinding
I am using MVVM architecture with databinding in my app. I am trying to display icons along with text like icons on the top and text below them and TabLayout positioned at the bottom of the screen. Code is as follows:
activity_main.xml:

sak
- 1,230
- 18
- 37
0
votes
1 answer
How to save data on online server using MVVM pattern in android
I am making an app using MVVM design pattern.Initially I tried adding data in offline database.Now I want to save data to online server.
Below is my code for offline data storage:
NoteDao.java
@Dao
public interface NoteDao {
@Insert
void…

Digvijay
- 2,887
- 3
- 36
- 86
0
votes
1 answer
If Android restarts my app, how can I make sure it doesn't load the most recent fragment?
My app consists of two activities: SignInActivity and MainActivity. SignInActivity lets the user sign in, and initializes a bunch of important variables the app needs to function properly. MainActivity contains a bunch of fragments that make up the…

user1114
- 1,071
- 2
- 15
- 33
0
votes
2 answers
How to make Room database insert method return int through mvvm architecture?
I want to get the id auto-generated while performing insert operation on Room database. I am implementing MVVM (Model-View-ViewModel) architecture which makes use of DAO to fire queries to Room database. I have added a repository layer between…

Rahul
- 143
- 1
- 17
0
votes
1 answer
How to databind livedata object (android)
Today I've some question about mvvm and databinding on android,
I'm trying to bind object properties on view.
I've an Object (Model) with some properties, by example :
public String name;
public String title;
public int value;
I've a ViewModel with…

C. MARTIN
- 43
- 12
0
votes
1 answer
Text Watcher Binding Adapter with ViewModel
I'm still new to all this MVVM and Android Architecture Components. I have a few screens (Login and Register) that have inputs for email, password, name etc and a 'continue' button that's only enabled when the required fields are filled out…

Nelson.b.austin
- 3,080
- 6
- 37
- 63
0
votes
1 answer
How to run same function synchronously and asynchronously
I am using Room and RxJava2 in Android application. I have a scenario inwhich I want to same function to run synchronously at some point and to run asynchronously on other place. Below is the function:
@Query("SELECT * from saved_survey WHERE…

Mustansar Saeed
- 2,730
- 2
- 22
- 46
0
votes
1 answer
How to write Unit test for ViewModel that contains RxJava/RxAndroid
I'm trying to refactor one pretty old project, so I started implementing new architecture (MVVM) with Dagger2, RxJava, RxAndroid... Now everything is connected and working fine, now the problem is, I have no idea how to write a Unit test for my…

joe
- 1,341
- 4
- 21
- 32
0
votes
0 answers
Am I using LiveData properly in this code? (works)
I'm new to Android development, and am trying to use a good pattern for accessing my data from a web service using ViewModel, Retrofit, LiveData. Looking for feedback on this pattern.
I went through a few iterations and online guides, and came up…

hexbinary
- 11
- 3
0
votes
1 answer
Android LiveData event sequence guarantees?
I have the following code in my Fragment, subscribing to my ViewModel's LiveData events.
viewModel.successfullyAddedEvent.observeEvent(this){
// do result handling by shared view model to the calling fragment
…

Jon O
- 6,532
- 1
- 46
- 57
0
votes
1 answer
Best practice to save changes of a RecyclerView list item when using MVVM and LiveData?
I followed this guide to understand how to use LiveData and data binding to update the UI when changes occur in the database and also save data back to the database when I make changes in the app.
The part I'm missing is how to properly extend the…

vicch
- 564
- 3
- 10
- 25