Skip to content Skip to sidebar Skip to footer

Will The `onchanged` Method Trigger Just As We Change The Data? Even If We Dont Change The State Of Activity?

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 happ

Solution 1:

Google actually described that (or very familiar to that) kind of issue as an anti-pattern on the dev-summit. The recommended approach is to use switchMap from android.arch.lifecycle.Transformations class. You can see the documentation page for more details.

Solution 2:

Try using this and delete the global MutableLiveData variable

publicMutableLiveData<GetHolidaysDatesFromServer> getHolidaysDatesFromServer(String upd_token,int product_id) {

       MutableLiveData<GetHolidaysDatesFromServer> MutableLiveDataGetHolidays=newMutableLiveData<>();

       //Your API call code goes herereturnMutableLiveDataGetHolidays;
 }

Post a Comment for "Will The `onchanged` Method Trigger Just As We Change The Data? Even If We Dont Change The State Of Activity?"