Questions tagged [android-mvvm]

0

votes
1

answer
22

Views

The need for a ViewModel Provider Factory

I was wondering why the ViewModel with different parameters in the constructor needs a ViewModel Provider Factory . Why can't a ViewModel be instantiated with a regular constructor new MyViewModel(parameter1 , parameter2);
Stavro Xhardha
1

votes
2

answer
33

Views

Android: Save FCM Notification to Room DB

I am using firebase FCM to get the notification. I want if the notification received, that should store in my RoomDatabase. Later on, when the user opens the app, then in notification section all notification will display. I am using MVVM, I was trying to save through ViewModel but it not work. Here...
Akash Chaubey
1

votes
1

answer
12

Views

How can test MutableLiveData<>.observe when the data is changed?

I have the next code for test if the API is working with Login function: @RunWith(RobolectricTestRunner.class) public class LoginTest { LoginRespository profileRepository = new LoginRespository(RuntimeEnvironment.application); @Test public void testLogin() { MutableLiveData data = new MutableLiveDat...
Tlaloc-ES
1

votes
0

answer
13

Views

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 ViewModel so that they can retrieve data using Live...
Cruces
1

votes
1

answer
255

Views

proper way to add a record and notify activity using room and mvvm

I am learning android mvvm structure and I have a doubt while implementing it. I was inserting a user object in database using room. But, I don't know how to notify the activity after inserting has done successfully. I have tried to implement it. But, It did not work. Let me show my code. RegisterAc...
Riddhi
1

votes
0

answer
251

Views

Injecting viewmodel dependency with dagger 2

I am having issues injecting a dependency into my viewModel. I keep getting Cannot create an instance of class ....viewModel.UserProfileViewModel. I have been trying to figure out this issue. Any suggestions would be really appreciated. Here is my code. I have seen in other questions that this is us...
user642206
1

votes
1

answer
439

Views

What are the differences between ViewModelProvider.Factory and ViewModelProvider.NewInstanceFactory?

I'm currently transforming my project architecture from MVP to MVVM. When I'm working on it, I find something made me confused: In ScheduleViewModelFactory.kt of project iosched, the factory implements ViewModelProvider.Factory: class ScheduleViewModelFactory( private val userEventRepository:Default...
Kazaf Chen
1

votes
1

answer
68

Views

Architecture Components and Intent Extras

Under the official architecture guidelines, is it still legit to pass data in form of intent extras from one activity to another (either forward with startActivity(ForResult) or back with setResult)? Furthermore, is it okay to populate views with this received data (for example with editText.setText...
Florian Walther
1

votes
2

answer
440

Views

Android bindingadapter not updating value

I am trying to use binding adapter to set image URL in 'imageView' with help of Picasso. My XML Image View: My ViewModel: public ObservableField getImageUrl() { return imageUrl; } private ObservableField imageUrl = new ObservableField(); @BindingAdapter({'bind:imgUrl'}) public static void setProfil...
Shivam
1

votes
1

answer
25

Views

How to initialize okHttp's MockServer() in a repository?

Server.kt (is a mock server that will return a list of Users) https://github.com/shalbert94/androidinterview/blob/master/server/src/main/java/com/jobrapp/server/Server.kt For some reason, val server = Server() called in my repository (https://github.com/shalbert94/androidinterview/blob/master/app/s...
Shalbert
1

votes
0

answer
52

Views

Can we use BaseObservable and LiveData together

How can I use LiveData and Baseobservable together in viewmodel so that I can use to pass data to activity and update UI by using them respectively
Sam
1

votes
1

answer
158

Views

how to communicate to activity/fragment from repository class for web service in MVVM architecture

I am new to MVVM architecture and i just want to know how to communicate between repository class and the UI (activity/fragment) class.I came across with live data which is doing this job for updating same entities from both (remote and room database). For example : 1) If i have entity named User....
Mohamed Niyaz
1

votes
1

answer
45

Views

How to show alertDialog Box using mvvm pattern

I am working on a login module where I have to show alert dialog if the login is unsuccessful. I have a authentication process in viewmodel and I have to display an error in alert dialog.How it can be done?
Sam
1

votes
0

answer
173

Views

Unable to display data from remote server using MVVM architecture in android

I am not able to parse json data from remote server. I am using MVVM architecture and volley library to parse json data. I tried to debug and the message says 'An attempt to invoke virtual method has been made on a null object reference'. I thought that the problem is due to LiveData class, so i re...
Osama
1

votes
0

answer
191

Views

Unit testing respository with in MVVM pattern android

I am trying to write unit tests for repository while using MVVM pattern in android. What i have is a repository which fetched data from the network using retrofit public class ValidateCbuRepository { private static ValidateCbuRepository single_instance = null; private MutableLiveData data = new Muta...
1

votes
1

answer
103

Views

How to show ProgressDialog when fetching data from ViewModel

I want to show ProgressDialog while fetching data from ViewModel and it works fine when I fetch data for the first time, but when I want to refresh the data from API the ProgressDialog starts and does not stops I create MutableLiveData() and try to manage the visibility but it's not working This is...
Akshay Katariya
1

votes
0

answer
51

Views

Is this really the best form of inject something with dagger 2? or why dagger is a good option?

I am trying to use Dagger 2, and in a lot of examples I saw code like this: MyComponent.java @Singleton @Component(modules = {SharedPrefModule.class}) public interface MyComponent { void inject(MainActivity activity); } SharedPrefModule.java @Module public class SharedPrefModule { private Context co...
Tlaloc-ES
1

votes
2

answer
92

Views

No Data displayed on recyclerview

I was learning mvvm structure and I made an application using the mvvm structure. I have used room and RxJava too. Code public class ScoresActivity extends AppCompatActivity { RecyclerView recyclerView; List scoreDataViewModelList; ScoreAdapter scoreAdapter; ScoreViewModel scoreViewModel; private f...
Riddhi
1

votes
1

answer
643

Views

Can we add multiple ViewModel.observer() method in a single activity

I have an activity that performs multiple background tasks, for example: getJWTToken(), sendFCMTokenToServer(), isPromoAvailable(), isForcedUpgradeRequired(), fetchNewsFromServer(), sendUserLatLngToServer() These all are network calls, and take some time. This is what i have done for 1 method. Ho...
Kirmani88
1

votes
1

answer
28

Views

Should 2 Activity's have separate ViewModels if the method usages don't overlap?

I have 1 Activity that only displays and deletes Notes from a RecyclerView. I have another Activity that only adds and updates new items. At the moment they both use the same ViewModel class: public class NoteViewModel extends AndroidViewModel { private NoteRepository repository; private LiveData al...
Florian Walther
1

votes
1

answer
32

Views

Bind view added at runtime with Data in MVVM

Adding run time view so how I can add that view data in MVVM. Here is the code FragmentHomeBinding fragmentHomeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false); FragmentHomeViewModel fragmentHomeViewModel = new FragmentHomeViewModel(getActivity()); fragmentHomeB...
Nikhil Singh
1

votes
1

answer
73

Views

android - using new thread in ViewModel class

I am using data mvvm architecture in my android app and filling xml item with data binding. in view model class I use AsyncTask for get data from database and this makes me some trouble. UI thread is called first and my xml items remains empty. what must I do?
faeze saghafi
1

votes
1

answer
60

Views

How can I synchronously subscribe to an observable so that I don't miss out on emissions from that observable?

I have an android app with an MVVM architecture. The view layer ( a fragment ) subscribes to an observable that is exposed by the ViewModel in the onStart(). Right after I call subscribe() on that observable, I make a direct invocation on the ViewModel that kicks things off. With this direct invocat...
Tyler Pfaff
1

votes
1

answer
182

Views

Is it possible to use paging library with MVP architecture in android?

I want to use paging library in my application, I have seen multiple sample they all are using view modal component with MVVM architecture, But most of the part of my application is in MVP architecture and I don't want to use MVVM, So is there any way to implement pagination with paging library with...
ramkrishna kushwaha
1

votes
1

answer
0

Views

It is ok to call observeForever() on Livedata returned by Transformations.map() inside ViewModel?

I tried to use LiveData Transformations.map() to check the result and update the UI. But Transformations.map() callback not triggered without an observer. So is it good way to call observeForever {} on livedata returned by Tranformations.map? And remove obervers on onCleared on ViewModel? private l...
Ramprasad
1

votes
1

answer
0

Views

How can concat two Integers in a TextView using Databinding?

I have a ViewModel with the next variables: public MutableLiveData questionPosition = new MutableLiveData(); public MutableLiveData totalQuestions = new MutableLiveData(); And I want show it in a TextView like questionPosition/totalQuestions (this is not a division) android:text='@={examViewModel.qu...
Tlaloc-ES
1

votes
1

answer
0

Views

is a bad practice expose the Activity in the XML layout in a MVVM app?

The general idea is that the XML Layout have a reference to the ViewModel like this: The question is that if is a bad practique expose too the activity like this: Because sometimes I only need call functions for open or close the activity, and I think that these are not a reason enough to create a n...
Tlaloc-ES
1

votes
1

answer
1.3k

Views

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 ViewModel class public class AddMarkerViewModel extends AndroidViewModel { private MarkerRepository mMarkerRepository; public ObservableFi...
Thracian
1

votes
1

answer
1.7k

Views

ViewModel injection (inside View) with MVVM Architecture

This is how I create an Adapter with MVVM (+Databinding) and Dagger-2.11-rc2: Adapter: public class ItemAdapter extends RecyclerView.Adapter{ private static int TYPE_A = 0; private static int TYPE_B = 1; ... @Override public BindableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if...
GuilhE
1

votes
2

answer
66

Views

How to show LoadingState when using Room Livedata MVVM

so I'm coming from an MVP background... What I'm basically trying to do is start a loadingView as soon as we start fetching the data from Room (SQLite), stop the loadingView when successful and all of that logic should be handled in my ViewModel (trying to keep my fragment clean) class for the Frag...
Mitch
1

votes
1

answer
1.9k

Views

Applying MVVM between ViewModel and Fragment/Activity interactions and communication

I am investing a lot of time into properly understanding of architecture components and the how everything fits into MVVM pattern. So far here's how I see things (without doing Dagger injection as I haven't got that far yet): a) UserEntity is a class with @Entity annotation to handle Room's table cr...
Alin
1

votes
1

answer
148

Views

Is View model in jetpack is same as view model in MVVM architecture?

I am a noob in MVVM architecture, I like to develop my future projects in this architecture. If I add and implement Android Jetpack Viewmodel class in my project and use them properly will it comes in MVVM architecture? Or is there a difference in MVVM's view model.?
Eldhopj
1

votes
2

answer
70

Views

The retrofit call not update viewmodel or viewmodel not update the view

I try get a user from a rest api for do login in my android app for get this I have the next code LoginActivity.java public class LoginActivity extends AppCompatActivity { private LoginViewModel loginViewModel; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate...
Tlaloc-ES
0

votes
3

answer
18

Views

The class cannot inherit from the AndroidViewModel, why?

I try create a new class that inherits from AndroidViewModel, like this public class LoginViewModel extends AndroidViewModel { public LoginViewModel() {} ... But I get this message in the ide: There is no default constructor available in 'android.arch.lifecycle.AndroidViewModel' My happen this? My g...
Tlaloc-ES
1

votes
3

answer
45

Views

How to use mvvm pattern using databinding

I am working on an application where there is a log in form.I am bit confused with the pattern as I don't understand as how I will open the new activity as my login is successful.As per my understanding when I click on submit button a method in viewmodel which authenticates will get call and after m...
Sam
6

votes
1

answer
1.6k

Views

MVVM Dagger2 A Binding With Matching Key Exists in Component

I am using the following google sample project: https://github.com/googlesamples/android-architecture-components as a reference for my new project and having difficulties trying to add a second activity to the project. Here is the error I get when compiling Error:(22, 8) error: [dagger.android.Andro...
Riley MacDonald
3

votes
1

answer
2.4k

Views

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 ObservableField. Whole ViewModel is passed to binding. In xml you jus...
Vadims Savjolovs
2

votes
1

answer
527

Views

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 edittext1. In that case, I want to request focus on edittext...
Riddhi
2

votes
1

answer
220

Views

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(), HasActivityInjector { @Inject lateinit var dispatchingAndroidInject...
Rupesh
1

votes
1

answer
789

Views

Databinding BR not showing all variable name

I have implemented DataBinding with MVVM pattern, here is my ViewModel class. public class MainViewModel extends BaseObservable { private String data, data1; @Bindable public String getData1() { return data1; } public void setData1(String data1) { this.data1 = data1; } @Bindable public String getDat...
Ravi Rupareliya

View additional questions