Which one to use in Room: LiveData or RxJava?












3














I am using Room for my Database management and I was confused in what to use while working with real-time data. For now, to manage real-time data I am using Flowable and am I pretty satisfied with it. What I was confused is I can use LiveData as well to do the same operation.



To give some context, here is how I am querying data and updating my view.



Flowable



addDisposable(userDao().getUsersFlowable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(users -> userAdapter.setUsers(users)));


LiveData



userDao().getUsersLiveData()
.observe(this, users -> {
userAdapter.setUsers(users)
})


I am not much familiar with LiveData, but as far as my research goes it is an observer pattern that is also lifecycle aware, meaning that I will stop notifying if UI is not in active state. That said, as you can see in my Flowable code, I am adding it to CompositeDisposable and I will dispose in my onDestroy() method.
So I don't see point of why I should use LiveData when I can manage everything with RxJava, which has a lot of operators for convenience.



So when should I use LiveData and when RxJava while working with Room. Answers reflecting given scenario is much appreciated, but other use cases are also welcomed.



I followed When to use RxJava in Android and when to use LiveData from Android Architectural Components?, but it's too broad and I couldn't get answer specifically in my case










share|improve this question





























    3














    I am using Room for my Database management and I was confused in what to use while working with real-time data. For now, to manage real-time data I am using Flowable and am I pretty satisfied with it. What I was confused is I can use LiveData as well to do the same operation.



    To give some context, here is how I am querying data and updating my view.



    Flowable



    addDisposable(userDao().getUsersFlowable()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(users -> userAdapter.setUsers(users)));


    LiveData



    userDao().getUsersLiveData()
    .observe(this, users -> {
    userAdapter.setUsers(users)
    })


    I am not much familiar with LiveData, but as far as my research goes it is an observer pattern that is also lifecycle aware, meaning that I will stop notifying if UI is not in active state. That said, as you can see in my Flowable code, I am adding it to CompositeDisposable and I will dispose in my onDestroy() method.
    So I don't see point of why I should use LiveData when I can manage everything with RxJava, which has a lot of operators for convenience.



    So when should I use LiveData and when RxJava while working with Room. Answers reflecting given scenario is much appreciated, but other use cases are also welcomed.



    I followed When to use RxJava in Android and when to use LiveData from Android Architectural Components?, but it's too broad and I couldn't get answer specifically in my case










    share|improve this question



























      3












      3








      3


      0





      I am using Room for my Database management and I was confused in what to use while working with real-time data. For now, to manage real-time data I am using Flowable and am I pretty satisfied with it. What I was confused is I can use LiveData as well to do the same operation.



      To give some context, here is how I am querying data and updating my view.



      Flowable



      addDisposable(userDao().getUsersFlowable()
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(users -> userAdapter.setUsers(users)));


      LiveData



      userDao().getUsersLiveData()
      .observe(this, users -> {
      userAdapter.setUsers(users)
      })


      I am not much familiar with LiveData, but as far as my research goes it is an observer pattern that is also lifecycle aware, meaning that I will stop notifying if UI is not in active state. That said, as you can see in my Flowable code, I am adding it to CompositeDisposable and I will dispose in my onDestroy() method.
      So I don't see point of why I should use LiveData when I can manage everything with RxJava, which has a lot of operators for convenience.



      So when should I use LiveData and when RxJava while working with Room. Answers reflecting given scenario is much appreciated, but other use cases are also welcomed.



      I followed When to use RxJava in Android and when to use LiveData from Android Architectural Components?, but it's too broad and I couldn't get answer specifically in my case










      share|improve this question















      I am using Room for my Database management and I was confused in what to use while working with real-time data. For now, to manage real-time data I am using Flowable and am I pretty satisfied with it. What I was confused is I can use LiveData as well to do the same operation.



      To give some context, here is how I am querying data and updating my view.



      Flowable



      addDisposable(userDao().getUsersFlowable()
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(users -> userAdapter.setUsers(users)));


      LiveData



      userDao().getUsersLiveData()
      .observe(this, users -> {
      userAdapter.setUsers(users)
      })


      I am not much familiar with LiveData, but as far as my research goes it is an observer pattern that is also lifecycle aware, meaning that I will stop notifying if UI is not in active state. That said, as you can see in my Flowable code, I am adding it to CompositeDisposable and I will dispose in my onDestroy() method.
      So I don't see point of why I should use LiveData when I can manage everything with RxJava, which has a lot of operators for convenience.



      So when should I use LiveData and when RxJava while working with Room. Answers reflecting given scenario is much appreciated, but other use cases are also welcomed.



      I followed When to use RxJava in Android and when to use LiveData from Android Architectural Components?, but it's too broad and I couldn't get answer specifically in my case







      rx-java rx-java2 android-room observer-pattern android-livedata






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 6:05

























      asked Nov 12 '18 at 2:49









      musooff

      322112




      322112
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Normally working with views it's often good to use LiveData. It automatically manages subscription, works really well with DataBinding library. it's sort of a data holder that is lifecycle aware as oppose to stream of data (Rx Concept).



          In other cases I would suggest using RxJava which has powerful operator chains for transformation and concurrency. Hope it sheds some lights on your understanding.






          share|improve this answer





















          • I guess that answers my question. Thanks
            – musooff
            Nov 13 '18 at 7:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255383%2fwhich-one-to-use-in-room-livedata-or-rxjava%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Normally working with views it's often good to use LiveData. It automatically manages subscription, works really well with DataBinding library. it's sort of a data holder that is lifecycle aware as oppose to stream of data (Rx Concept).



          In other cases I would suggest using RxJava which has powerful operator chains for transformation and concurrency. Hope it sheds some lights on your understanding.






          share|improve this answer





















          • I guess that answers my question. Thanks
            – musooff
            Nov 13 '18 at 7:24
















          1














          Normally working with views it's often good to use LiveData. It automatically manages subscription, works really well with DataBinding library. it's sort of a data holder that is lifecycle aware as oppose to stream of data (Rx Concept).



          In other cases I would suggest using RxJava which has powerful operator chains for transformation and concurrency. Hope it sheds some lights on your understanding.






          share|improve this answer





















          • I guess that answers my question. Thanks
            – musooff
            Nov 13 '18 at 7:24














          1












          1








          1






          Normally working with views it's often good to use LiveData. It automatically manages subscription, works really well with DataBinding library. it's sort of a data holder that is lifecycle aware as oppose to stream of data (Rx Concept).



          In other cases I would suggest using RxJava which has powerful operator chains for transformation and concurrency. Hope it sheds some lights on your understanding.






          share|improve this answer












          Normally working with views it's often good to use LiveData. It automatically manages subscription, works really well with DataBinding library. it's sort of a data holder that is lifecycle aware as oppose to stream of data (Rx Concept).



          In other cases I would suggest using RxJava which has powerful operator chains for transformation and concurrency. Hope it sheds some lights on your understanding.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 6:19









          Samuel Robert

          3,29052034




          3,29052034












          • I guess that answers my question. Thanks
            – musooff
            Nov 13 '18 at 7:24


















          • I guess that answers my question. Thanks
            – musooff
            Nov 13 '18 at 7:24
















          I guess that answers my question. Thanks
          – musooff
          Nov 13 '18 at 7:24




          I guess that answers my question. Thanks
          – musooff
          Nov 13 '18 at 7:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255383%2fwhich-one-to-use-in-room-livedata-or-rxjava%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation