Tags down


How to use data from onActivityResult in MVVM architecture?

By : arctair
Date : September 17 2020, 04:00 AM
hop of those help? IN MVVM Architecture, you don't need to exchange data using Activity's onActivityResult. Instead, let target Activity's UI bind to ViewModel's LiveData which further points to same data source (e.g. sqLite) that is updated by another activity (via its own ViewModel).
code :

Share : facebook icon twitter icon

MVVM architecture - user rights and fetching data

By : hCasares
Date : March 29 2020, 07:55 AM
Hope that helps Your DAL is the one that should fetch and filter the results based on the user's permissions. In other words, the VM should only receive the Model/Data that the user is allowed to see.
The VM enforces business rules as you said, but I'm not sure Model filtering fits into this category.

How get extjs-6 sotre's data in mvvm architecture?

By : Jian Zhai
Date : March 29 2020, 07:55 AM
this one helps. you are using it correctly. You have to use users.getData().items as follow:
app = MyApp.getApplication(); users = app.getStore('User'); users.getData().items;

Use Tab layout in MVVM architecture with the data binding library

By : user6382850
Date : March 29 2020, 07:55 AM
Hope that helps I am developing an app that has tab layout as the image. , MainActivity -
code :
public class MainActivity extends Activity 
    protected void onCreate(@Nullable final Bundle savedInstanceState)
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

    public static void bindViewPagerAdapter(final ViewPager view, final MainActivity activity)
        final MainActionsAdapter adapter = new MainActionsAdapter(view.getContext(), activity.getSupportFragmentManager());

    public static void bindViewPagerTabs(final TabLayout view, final ViewPager pagerView)
        view.setupWithViewPager(pagerView, true);

<layout xmlns:android="http://schemas.android.com/apk/res/android"


        <import type="android.view.View" />

            type="com.ui.main.MainActivity" />

            type="android.support.v4.app.FragmentManager" />


            app:titleMarginStart="8dp" />


            app:handler="@{handler}" />


public class MainSectionsAdapter extends FragmentPagerAdapter
    private static final int CONTACTS = 0;
    private static final int CALLS = 1;
    private static final int CHATS = 2;

    private static final int[] TABS = new int[]{CONTACTS, CALLS, CHATS};

    private Context mContext;

    public MainSectionsAdapter(final Context context, final FragmentManager fm)
        mContext = context.getApplicationContext();

    public Fragment getItem(int position)
        switch (TABS[position])
            case CONTACTS:
                return ContactsFragment.newInstance();
            case CALLS:
                return CallsFragment.newInstance();
            case CHATS:
                return ChatsFragment.newInstance();
        return null;

    public int getCount()
        return TABS.length;

    public CharSequence getPageTitle(int position)
        switch (TABS[position])
            case CONTACTS:
                return mContext.getResources().getString(R.string.contacts);
            case CALLS:
                return mContext.getResources().getString(R.string.calls);
            case CHATS:
                return mContext.getResources().getString(R.string.chats);
        return null;

Android MVVM architecture and observing changes on data from an API

By : 4everdye
Date : March 29 2020, 07:55 AM
hope this fix your issue Your code is not working due to a new live data instance be created whenever getDeals() is called and the api response value be informed to other live data instance. You must set api response value to same instance of MutableLiveData returned by getDeals()
I'm not saying that it is the best architectural solution, but if you create a mutable live data as a class attribute and return it whenever getDeals() is called. Probably, it's going to work.
code :
    import com.example.android_client.models.Deal;
    import com.google.gson.Gson;
    import org.jetbrains.annotations.NotNull;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    import okhttp3.Call;
    import okhttp3.Callback;
    import okhttp3.OkHttpClient;
    import okhttp3.Request;
    import okhttp3.Response;
    import okhttp3.ResponseBody;

        public class Repository {

        private static Repository instance;
        private ArrayList<Deal> dealsList = new ArrayList<>();
        private final OkHttpClient client = new OkHttpClient();
        private MutableLiveData<List<Deal>> _deals = new MutableLiveData<>();                         
        private LiveData<List<Deal>> deals = _deals

        public static Repository getInstance() {
            if(instance == null) {
                instance = new Repository();
            return instance;

        private Repository() {}

        public LiveData<List<Deal>> getDeals() {
            return deals;

        private void setDeals() {
            Request request = new Request.Builder()
                    .url("<params here>")

            client.newCall(request).enqueue(new Callback() {
                public void onFailure(@NotNull Call call, @NotNull IOException e) {

                public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                    try (ResponseBody responseBody = response.body()) {
                        if (!response.isSuccessful()) {
                            throw new IOException("Unexpected code " + response);
                        String jsonDeals = responseBody.string(); // can only call string() once or you'll get an IllegalStateException
                        Deal[] deals = new Gson().fromJson(jsonDeals, Deal[].class);
                        dealsList = new ArrayList<>(Arrays.asList(deals));




Retrieving Data from FireStore using MVVM Architecture

By : big_Al
Date : March 29 2020, 07:55 AM
it fixes the issue Instead of interface I only use LiveData to bring the data to a recyclerview, for example.
First, We have to create our Firestore query. In this example, I am listing all documents inside a collection.
code :
public class FirestoreLiveData<T> extends LiveData<T> {

    public static final String TAG = "debinf firestore";

    private ListenerRegistration registration;

    private CollectionReference colRef;
    private Class clazz;

    public FirestoreLiveData(CollectionReference colRef, Class clazz) {
        this.colRef = colRef;
        this.clazz = clazz;

    EventListener<QuerySnapshot> eventListener = new EventListener<QuerySnapshot>() {
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            if (e != null) {
                Log.i(TAG, "Listen failed.", e);

            if (queryDocumentSnapshots != null && !queryDocumentSnapshots.isEmpty()) {
                List<T> itemList = new ArrayList<>();
                for (DocumentSnapshot snapshot : queryDocumentSnapshots.getDocuments()) {
                    T item = (T) snapshot.toObject(clazz);
                    Log.i(TAG, "snapshot is "+snapshot.getId());
                setValue((T) itemList);

    protected void onActive() {
        registration = colRef.addSnapshotListener(eventListener);

    protected void onInactive() {
        if (!hasActiveObservers()) {
            registration = null;
public class Repository {

    public Repository() {

    public LiveData<List<ProductsObject>> productListening(GroupObject group) {
        return new FirestoreLiveData<>(DatabaseRouter.getCollectionRef(group.getGroupCreator()).document(group.getGroupKey()).collection("ProductList"), ProductsObject.class);

public class MyViewModel extends ViewModel {

    Repository repository = new Repository();

    public LiveData<List<ProductsObject>> getProductList(GroupObject groupObject) {
        return repository.productListening(groupObject);

    viewModel = ViewModelProviders.of(this).get(MyViewModel.class);
    viewModel.getProductList(groupObject).observe(this, new Observer<List<ProductsObject>>() {
        public void onChanged(@Nullable List<ProductsObject> productsObjects) {
            //Log.i(TAG, "viewModel: productsObjects is "+productsObjects.get(0).getCode());
Related Posts Related Posts :
  • Designing Huge Data input form in Android
  • how to set custom click in notification android
  • flutter simple text example
  • How to update a specific node based on another node in firebase realtime database android
  • Having a textview below another textview that is centered?
  • RecyclerView inside a Dialog is overlapping other content of dialog
  • Jenkins Android building pipeline from different Git repositories
  • load large amount of data in android spinner blocks UI
  • How to add layout header in CustomTabsIntent
  • What is better to use Dagger 2 or Koin in Android app
  • How to save fragment state while navigating with navigation component
  • For online Android games, what services are available to ensure the integrity of the APK file to prevent cheating?
  • Google removed my app without any notice. Has this happened to others?
  • Firebase database search returned no results
  • How to retry a request inside my viewmodel
  • how to use getItemAtPosition in my spinner from firebase in google map using android studio
  • ARCore – Object does not show in correct depth in Face Augmentation
  • Android - Get status codes of web pages opened in browser
  • How to add drawablePadding only for one side
  • How to get Device unique Id in my android application?
  • Bottom navigation doesn't show fragments in android jet pack navigation graph
  • React Native Firebase - Push data to Array allowing to display in a FlatList
  • Android image capture, how to get the lowest quality picture to take less space
  • Functions are not valid as a react child.This may happen if you return a component instead of <Component/> from re
  • Firestore get documents with maximum value
  • How to Rename and Generate all APK & Bundle from Gradle with Product flavour and APK Splits
  • How do I deploy custom Image Processing algorithms in an android app?
  • How to save data offline in flutter
  • How do I add .cpp included files to the dependencies in android.mk?
  • Is there compulsion of using `FrameLayout` for loading fragments?
  • Difference between globalScope , corountineScope and viewScope in Kotlin
  • Can a device admin in android install a package?
  • Can two Apps (owner and client) share same database with different authentication spaces?
  • Set Text Radio Button from JSON Android Studio - AlertDialog
  • How to change the toolbar's home button color in androidx?
  • Could you tell me why the author need to wrap FrameLayout for Fragment?
  • How to convert string value to JSONArray in android
  • Android PDF viewer crashes when app is minified
  • Edittext aftertextchange triggers multiple times when text changed programmatically
  • When to use JobIntentService vs WorkManager?
  • how to remove all markers and polyline from google map in android?
  • How to convert JsonObject to class model kotlin android
  • Density DPI of Samsung Galaxy S10 too small?
  • Android Fusedlocationproviderclient not working with APN Sim its working with Wifi or ordinary internet or Offline
  • How to refresh the token generated by lambda API using retrofit?
  • Why should I take advantage to this design?
  • I can't exist from map's iteration
  • How to remove battery optimisation in android programmatically?
  • Used flutter_svg package but SVG files are not rendering in bottomnavigation bar
  • How to load GIF continuously on video in android using FFMPEG?
  • Render a shape upon mouse click using Libgdx (Android)
  • ERROR: Failed to resolve: com.google.firebase:firebase-messaging:19.2.0
  • React Native disable console.warn yellow box from the app screen bottom
  • Prevent Android App from getting installed on multiple users
  • App is crashing when installed from Google Play store
  • Fragments not added to backstack using Navigation Components
  • Do we still need to include `kapt com.android.databinding:compiler`
  • Return from all loops and return value
  • Android: Can I use google cloud storage API for SDK less than 26?
  • Android: How to call a function on click of an invisible button?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk