Will the onChanged
method be called if we dont change the state of the activity or restart the activity? ( Even if the data changes ) . If it doesnt happen how shall i make it happen ?
onCreate() {
viewModel.getHolidaysDatesFromServer(..).observe(.....this,new Observer<GetHolidaysDatesFromServer>) {
onChanged(GetHolidaysDatesFromServer GetHolidaysDatesFromServer)
}
}
and my ViewModel class ...
public class CalendarLifeCycleOwner extends AndroidViewModel {
Context context;
MutableLiveData<GetHolidaysDatesFromServer> MutableLiveDataGetHolidays=new MutableLiveData<>();
public CalendarLifeCycleOwner(@NonNull Application application) {
super(application);
this.context=application.getApplicationContext();
}
public MutableLiveData<GetHolidaysDatesFromServer> getHolidaysDatesFromServer(String upd_token,int product_id) {
JustProductId justProductId=new JustProductId();
justProductId.setProduct_id(product_id);
UserListInterface userListInterface= UserListService.createService(UserListInterface.class, Utility.ACCEPT_HEADER_V4);
Call<GetHolidaysDatesFromServer> getHolidaysDatesFromServerCall=userListInterface.GetProductHolidays(upd_token,justProductId);
getHolidaysDatesFromServerCall.enqueue(new Callback<GetHolidaysDatesFromServer>() {
@Override
public void onResponse(Call<GetHolidaysDatesFromServer> call, Response<GetHolidaysDatesFromServer> response) {
if (response.isSuccessful()) {
GetHolidaysDatesFromServer getHolidaysDatesFromServer=response.body();
MutableLiveDataGetHolidays.postValue(getHolidaysDatesFromServer);
}
}
@Override
public void onFailure(Call<GetHolidaysDatesFromServer> call, Throwable t) {
ErrorObject errorObject=new ErrorObject(t);
GetHolidaysDatesFromServer getHolidaysDatesFromServer=new GetHolidaysDatesFromServer();
getHolidaysDatesFromServer.setErrorObject(errorObject);
MutableLiveDataGetHolidays.setValue(getHolidaysDatesFromServer);
}
});
return MutableLiveDataGetHolidays;
}
}
But after i just change the data onChanged()
is not getting called ...
.observe(....)
to make it trigger ..?? i have observed inoCreate
once – PrecastViewModel
with MutableLiveData ...1st time in onCreate its getting called if the data is changed ...but after that even if the data changes onChanged is not called – PrecastViewModel
class code – PrecastonCreate
– PrecastonRespone()
callback and check that is itrespone.isSuccessfull()
is true ?...that's the only thing i have to say – Featured