Pass value from single across completable to result in rxjava AndroidStrange out of memory issue while loading an image to a Bitmap objectFling gesture detection on grid layoutHow do I pass data between Activities in Android application?How to pass an object from one activity to another on AndroidRxJava flat map: what happens when one of the resulting observable complete?RxJava2 Convert two Single's into CompletableRxjava observeOn and subscribeOn in RetrofitParallel api request using Single.zip not handling errorRxAndroid operator retryWhen is invoked but does not resubscribeObservable do not call onComplete (sqlbrite - mapToOneOrDefault)

Are there historical examples of audiences drawn to a work that was "so bad it's good"?

Why'd a rational buyer offer to buy with no conditions precedent?

Does water in vacuum form a solid shell or freeze solid?

How to deceive the MC

How does Dreadhorde Arcanist interact with split cards?

Why does the hash of infinity have the digits of π?

Can flying creatures choose to hover, even if they don't have hover in their flying speed?

What is the use case for non-breathable waterproof pants?

Are there any German nonsense poems (Jabberwocky)?

Why did other houses not demand this?

Cisco 3750X Power Cable

How to write numbers and percentage?

How does the Earth's center produce heat?

Why does the painters tape have to be blue?

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

Can a UK national work as a paid shop assistant in the USA?

The disk image is 497GB smaller than the target device

What is to the west of Westeros?

Is there a simple example that empirical evidence is misleading?

Knight's Tour on a 7x7 Board starting from D5

Is it normal to "extract a paper" from a master thesis?

What did Brienne write about Jaime?

Quantum corrections to geometry

Unary Enumeration



Pass value from single across completable to result in rxjava Android


Strange out of memory issue while loading an image to a Bitmap objectFling gesture detection on grid layoutHow do I pass data between Activities in Android application?How to pass an object from one activity to another on AndroidRxJava flat map: what happens when one of the resulting observable complete?RxJava2 Convert two Single's into CompletableRxjava observeOn and subscribeOn in RetrofitParallel api request using Single.zip not handling errorRxAndroid operator retryWhen is invoked but does not resubscribeObservable do not call onComplete (sqlbrite - mapToOneOrDefault)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















This is what I want:




  1. Check if I have data about products in database.

  2. If I have data I run Single to get data from DB.

  3. If not I run Single for get data from backend

  4. If I get response I want to save data in DB using Completable.

  5. After saving data I want to map values from step 2 or 3 to view model

  6. In result I want to send data to activity.



This is what I have now:



checkProductsInDBUseCase.run()
.flatMap
if (it)
getProductsFromDBUseCase.run()
else
getProductsUseCase.run(3)

.map
it.products.map item -> item.toViewModel()

.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onSuccess =
view.showBikes(it)
,
onError =
view.showBikesError(it.message.toString())

).addTo(disposables)


Between flat map and map I need to run saveDataUseCase(it), but I don't know how to pass itfrom completable to map. Any ideas?










share|improve this question






























    0















    This is what I want:




    1. Check if I have data about products in database.

    2. If I have data I run Single to get data from DB.

    3. If not I run Single for get data from backend

    4. If I get response I want to save data in DB using Completable.

    5. After saving data I want to map values from step 2 or 3 to view model

    6. In result I want to send data to activity.



    This is what I have now:



    checkProductsInDBUseCase.run()
    .flatMap
    if (it)
    getProductsFromDBUseCase.run()
    else
    getProductsUseCase.run(3)

    .map
    it.products.map item -> item.toViewModel()

    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeBy(
    onSuccess =
    view.showBikes(it)
    ,
    onError =
    view.showBikesError(it.message.toString())

    ).addTo(disposables)


    Between flat map and map I need to run saveDataUseCase(it), but I don't know how to pass itfrom completable to map. Any ideas?










    share|improve this question


























      0












      0








      0








      This is what I want:




      1. Check if I have data about products in database.

      2. If I have data I run Single to get data from DB.

      3. If not I run Single for get data from backend

      4. If I get response I want to save data in DB using Completable.

      5. After saving data I want to map values from step 2 or 3 to view model

      6. In result I want to send data to activity.



      This is what I have now:



      checkProductsInDBUseCase.run()
      .flatMap
      if (it)
      getProductsFromDBUseCase.run()
      else
      getProductsUseCase.run(3)

      .map
      it.products.map item -> item.toViewModel()

      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeBy(
      onSuccess =
      view.showBikes(it)
      ,
      onError =
      view.showBikesError(it.message.toString())

      ).addTo(disposables)


      Between flat map and map I need to run saveDataUseCase(it), but I don't know how to pass itfrom completable to map. Any ideas?










      share|improve this question
















      This is what I want:




      1. Check if I have data about products in database.

      2. If I have data I run Single to get data from DB.

      3. If not I run Single for get data from backend

      4. If I get response I want to save data in DB using Completable.

      5. After saving data I want to map values from step 2 or 3 to view model

      6. In result I want to send data to activity.



      This is what I have now:



      checkProductsInDBUseCase.run()
      .flatMap
      if (it)
      getProductsFromDBUseCase.run()
      else
      getProductsUseCase.run(3)

      .map
      it.products.map item -> item.toViewModel()

      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeBy(
      onSuccess =
      view.showBikes(it)
      ,
      onError =
      view.showBikesError(it.message.toString())

      ).addTo(disposables)


      Between flat map and map I need to run saveDataUseCase(it), but I don't know how to pass itfrom completable to map. Any ideas?







      android rx-java2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 6:07









      Tanveer Munir

      1,7051422




      1,7051422










      asked Mar 23 at 21:40









      edi233edi233

      1,446103875




      1,446103875






















          2 Answers
          2






          active

          oldest

          votes


















          1














          If your saveDataUseCase() is Completable then you can do this



          checkProductsInDBUseCase.run()
          .flatMap
          if (it)
          getProductsFromDBUseCase.run()
          else
          getProductsUseCase.run(3)


          .faltMap
          saveDataUseCase(it).toSingleDefault(it)

          .map
          it.products.map item -> item.toViewModel()

          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
          .subscribeBy(
          onSuccess =
          view.showBikes(it)
          ,
          onError =
          view.showBikesError(it.message.toString())

          ).addTo(disposables)


          But if you change return type of saveDataUseCase() to Unit, you can use Fred's answer. It would be better






          share|improve this answer






























            0














            Here I'd use doOnSuccess. This seems ideal especially because you're creating a side effect, which we usually use the doOnXXX methods for.



            checkProductsInDBUseCase.run()
            .flatMap
            if (it)
            getProductsFromDBUseCase.run()
            else
            getProductsUseCase.run(3)


            .doOnSuccess
            saveDataUseCase(it)

            .map
            it.products.map item -> item.toViewModel()

            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeBy(
            onSuccess =
            view.showBikes(it)
            ,
            onError =
            view.showBikesError(it.message.toString())

            ).addTo(disposables)


            The method will not change the result of the flatMap so you will still get the correct object inside the map function.






            share|improve this answer























              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%2f55318661%2fpass-value-from-single-across-completable-to-result-in-rxjava-android%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              If your saveDataUseCase() is Completable then you can do this



              checkProductsInDBUseCase.run()
              .flatMap
              if (it)
              getProductsFromDBUseCase.run()
              else
              getProductsUseCase.run(3)


              .faltMap
              saveDataUseCase(it).toSingleDefault(it)

              .map
              it.products.map item -> item.toViewModel()

              .subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribeBy(
              onSuccess =
              view.showBikes(it)
              ,
              onError =
              view.showBikesError(it.message.toString())

              ).addTo(disposables)


              But if you change return type of saveDataUseCase() to Unit, you can use Fred's answer. It would be better






              share|improve this answer



























                1














                If your saveDataUseCase() is Completable then you can do this



                checkProductsInDBUseCase.run()
                .flatMap
                if (it)
                getProductsFromDBUseCase.run()
                else
                getProductsUseCase.run(3)


                .faltMap
                saveDataUseCase(it).toSingleDefault(it)

                .map
                it.products.map item -> item.toViewModel()

                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeBy(
                onSuccess =
                view.showBikes(it)
                ,
                onError =
                view.showBikesError(it.message.toString())

                ).addTo(disposables)


                But if you change return type of saveDataUseCase() to Unit, you can use Fred's answer. It would be better






                share|improve this answer

























                  1












                  1








                  1







                  If your saveDataUseCase() is Completable then you can do this



                  checkProductsInDBUseCase.run()
                  .flatMap
                  if (it)
                  getProductsFromDBUseCase.run()
                  else
                  getProductsUseCase.run(3)


                  .faltMap
                  saveDataUseCase(it).toSingleDefault(it)

                  .map
                  it.products.map item -> item.toViewModel()

                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeBy(
                  onSuccess =
                  view.showBikes(it)
                  ,
                  onError =
                  view.showBikesError(it.message.toString())

                  ).addTo(disposables)


                  But if you change return type of saveDataUseCase() to Unit, you can use Fred's answer. It would be better






                  share|improve this answer













                  If your saveDataUseCase() is Completable then you can do this



                  checkProductsInDBUseCase.run()
                  .flatMap
                  if (it)
                  getProductsFromDBUseCase.run()
                  else
                  getProductsUseCase.run(3)


                  .faltMap
                  saveDataUseCase(it).toSingleDefault(it)

                  .map
                  it.products.map item -> item.toViewModel()

                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeBy(
                  onSuccess =
                  view.showBikes(it)
                  ,
                  onError =
                  view.showBikesError(it.message.toString())

                  ).addTo(disposables)


                  But if you change return type of saveDataUseCase() to Unit, you can use Fred's answer. It would be better







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 6:31









                  Andrey MatyushinAndrey Matyushin

                  363




                  363























                      0














                      Here I'd use doOnSuccess. This seems ideal especially because you're creating a side effect, which we usually use the doOnXXX methods for.



                      checkProductsInDBUseCase.run()
                      .flatMap
                      if (it)
                      getProductsFromDBUseCase.run()
                      else
                      getProductsUseCase.run(3)


                      .doOnSuccess
                      saveDataUseCase(it)

                      .map
                      it.products.map item -> item.toViewModel()

                      .subscribeOn(Schedulers.io())
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribeBy(
                      onSuccess =
                      view.showBikes(it)
                      ,
                      onError =
                      view.showBikesError(it.message.toString())

                      ).addTo(disposables)


                      The method will not change the result of the flatMap so you will still get the correct object inside the map function.






                      share|improve this answer



























                        0














                        Here I'd use doOnSuccess. This seems ideal especially because you're creating a side effect, which we usually use the doOnXXX methods for.



                        checkProductsInDBUseCase.run()
                        .flatMap
                        if (it)
                        getProductsFromDBUseCase.run()
                        else
                        getProductsUseCase.run(3)


                        .doOnSuccess
                        saveDataUseCase(it)

                        .map
                        it.products.map item -> item.toViewModel()

                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeBy(
                        onSuccess =
                        view.showBikes(it)
                        ,
                        onError =
                        view.showBikesError(it.message.toString())

                        ).addTo(disposables)


                        The method will not change the result of the flatMap so you will still get the correct object inside the map function.






                        share|improve this answer

























                          0












                          0








                          0







                          Here I'd use doOnSuccess. This seems ideal especially because you're creating a side effect, which we usually use the doOnXXX methods for.



                          checkProductsInDBUseCase.run()
                          .flatMap
                          if (it)
                          getProductsFromDBUseCase.run()
                          else
                          getProductsUseCase.run(3)


                          .doOnSuccess
                          saveDataUseCase(it)

                          .map
                          it.products.map item -> item.toViewModel()

                          .subscribeOn(Schedulers.io())
                          .observeOn(AndroidSchedulers.mainThread())
                          .subscribeBy(
                          onSuccess =
                          view.showBikes(it)
                          ,
                          onError =
                          view.showBikesError(it.message.toString())

                          ).addTo(disposables)


                          The method will not change the result of the flatMap so you will still get the correct object inside the map function.






                          share|improve this answer













                          Here I'd use doOnSuccess. This seems ideal especially because you're creating a side effect, which we usually use the doOnXXX methods for.



                          checkProductsInDBUseCase.run()
                          .flatMap
                          if (it)
                          getProductsFromDBUseCase.run()
                          else
                          getProductsUseCase.run(3)


                          .doOnSuccess
                          saveDataUseCase(it)

                          .map
                          it.products.map item -> item.toViewModel()

                          .subscribeOn(Schedulers.io())
                          .observeOn(AndroidSchedulers.mainThread())
                          .subscribeBy(
                          onSuccess =
                          view.showBikes(it)
                          ,
                          onError =
                          view.showBikesError(it.message.toString())

                          ).addTo(disposables)


                          The method will not change the result of the flatMap so you will still get the correct object inside the map function.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 24 at 3:15









                          FredFred

                          9,18012846




                          9,18012846



























                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318661%2fpass-value-from-single-across-completable-to-result-in-rxjava-android%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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript