Android Architecture Components - communication between Activity/Fragment and Service/IntentService












1















The answer to this question is providing me with a marvelous guide to how to use services in the Android Architecture Components/Jetpack environment.



It suggests that IntentServices should just plug into ViewModels via Repositories, as if they were any other data source, like a web service.



But neither that answer nor the Jetpack guide upon which it's based have much information about the so-called "Remote Data Source" object that would start and bind to the service, observe its LiveData and cascade it back up to the Repository.



What is it? An ordinary Java object that gets injected into the Repository? A singleton? Some special Lifecycle-aware subclass?



Where does it get the context it needs to start the service?



Is there example code you can point me to? If not, could you just sketch out the basics of what that would look like, including how its lifecycle would be linked to the lifecycle of the service itself, for newbies like me?



enter image description here



Thanks in advance!










share|improve this question





























    1















    The answer to this question is providing me with a marvelous guide to how to use services in the Android Architecture Components/Jetpack environment.



    It suggests that IntentServices should just plug into ViewModels via Repositories, as if they were any other data source, like a web service.



    But neither that answer nor the Jetpack guide upon which it's based have much information about the so-called "Remote Data Source" object that would start and bind to the service, observe its LiveData and cascade it back up to the Repository.



    What is it? An ordinary Java object that gets injected into the Repository? A singleton? Some special Lifecycle-aware subclass?



    Where does it get the context it needs to start the service?



    Is there example code you can point me to? If not, could you just sketch out the basics of what that would look like, including how its lifecycle would be linked to the lifecycle of the service itself, for newbies like me?



    enter image description here



    Thanks in advance!










    share|improve this question



























      1












      1








      1








      The answer to this question is providing me with a marvelous guide to how to use services in the Android Architecture Components/Jetpack environment.



      It suggests that IntentServices should just plug into ViewModels via Repositories, as if they were any other data source, like a web service.



      But neither that answer nor the Jetpack guide upon which it's based have much information about the so-called "Remote Data Source" object that would start and bind to the service, observe its LiveData and cascade it back up to the Repository.



      What is it? An ordinary Java object that gets injected into the Repository? A singleton? Some special Lifecycle-aware subclass?



      Where does it get the context it needs to start the service?



      Is there example code you can point me to? If not, could you just sketch out the basics of what that would look like, including how its lifecycle would be linked to the lifecycle of the service itself, for newbies like me?



      enter image description here



      Thanks in advance!










      share|improve this question
















      The answer to this question is providing me with a marvelous guide to how to use services in the Android Architecture Components/Jetpack environment.



      It suggests that IntentServices should just plug into ViewModels via Repositories, as if they were any other data source, like a web service.



      But neither that answer nor the Jetpack guide upon which it's based have much information about the so-called "Remote Data Source" object that would start and bind to the service, observe its LiveData and cascade it back up to the Repository.



      What is it? An ordinary Java object that gets injected into the Repository? A singleton? Some special Lifecycle-aware subclass?



      Where does it get the context it needs to start the service?



      Is there example code you can point me to? If not, could you just sketch out the basics of what that would look like, including how its lifecycle would be linked to the lifecycle of the service itself, for newbies like me?



      enter image description here



      Thanks in advance!







      android android-service-binding android-jetpack






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 3:53







      John

















      asked Nov 14 '18 at 3:13









      JohnJohn

      1,02021026




      1,02021026
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Please follow this link. You will get your answer and also a basic implementation.



          https://android.jlelse.eu/android-architecture-components-now-with-100-more-mvvm-11629a630125






          share|improve this answer
























          • Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

            – John
            Nov 14 '18 at 4:01











          • There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

            – Sultan Mahmud
            Nov 14 '18 at 4:21



















          0














          Why do you want to use the service? Remote Data Source typically means a layer that fetches data from your web back end API using a library such as Retrofit. You don't need a Service for that.






          share|improve this answer
























          • My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

            – John
            Nov 14 '18 at 5:22











          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%2f53292669%2fandroid-architecture-components-communication-between-activity-fragment-and-se%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









          0














          Please follow this link. You will get your answer and also a basic implementation.



          https://android.jlelse.eu/android-architecture-components-now-with-100-more-mvvm-11629a630125






          share|improve this answer
























          • Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

            – John
            Nov 14 '18 at 4:01











          • There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

            – Sultan Mahmud
            Nov 14 '18 at 4:21
















          0














          Please follow this link. You will get your answer and also a basic implementation.



          https://android.jlelse.eu/android-architecture-components-now-with-100-more-mvvm-11629a630125






          share|improve this answer
























          • Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

            – John
            Nov 14 '18 at 4:01











          • There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

            – Sultan Mahmud
            Nov 14 '18 at 4:21














          0












          0








          0







          Please follow this link. You will get your answer and also a basic implementation.



          https://android.jlelse.eu/android-architecture-components-now-with-100-more-mvvm-11629a630125






          share|improve this answer













          Please follow this link. You will get your answer and also a basic implementation.



          https://android.jlelse.eu/android-architecture-components-now-with-100-more-mvvm-11629a630125







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 3:31









          Sultan MahmudSultan Mahmud

          23017




          23017













          • Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

            – John
            Nov 14 '18 at 4:01











          • There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

            – Sultan Mahmud
            Nov 14 '18 at 4:21



















          • Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

            – John
            Nov 14 '18 at 4:01











          • There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

            – Sultan Mahmud
            Nov 14 '18 at 4:21

















          Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

          – John
          Nov 14 '18 at 4:01





          Are you talking about the "RemoteRepository" that the blog refers to? I can't see an implementation of it, just references to it.

          – John
          Nov 14 '18 at 4:01













          There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

          – Sultan Mahmud
          Nov 14 '18 at 4:21





          There is a reference to the full project. Here it is: github.com/JoaquimLey/transport-eta/tree/…

          – Sultan Mahmud
          Nov 14 '18 at 4:21













          0














          Why do you want to use the service? Remote Data Source typically means a layer that fetches data from your web back end API using a library such as Retrofit. You don't need a Service for that.






          share|improve this answer
























          • My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

            – John
            Nov 14 '18 at 5:22
















          0














          Why do you want to use the service? Remote Data Source typically means a layer that fetches data from your web back end API using a library such as Retrofit. You don't need a Service for that.






          share|improve this answer
























          • My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

            – John
            Nov 14 '18 at 5:22














          0












          0








          0







          Why do you want to use the service? Remote Data Source typically means a layer that fetches data from your web back end API using a library such as Retrofit. You don't need a Service for that.






          share|improve this answer













          Why do you want to use the service? Remote Data Source typically means a layer that fetches data from your web back end API using a library such as Retrofit. You don't need a Service for that.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 4:59









          Samuel RobertSamuel Robert

          3,43552134




          3,43552134













          • My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

            – John
            Nov 14 '18 at 5:22



















          • My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

            – John
            Nov 14 '18 at 5:22

















          My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

          – John
          Nov 14 '18 at 5:22





          My service does audio recording. The answer I refer to above says that intent services can be treated as remote services for purposes of the JetPack architecture. But I'm open to other suggestions on where in the architecture I should start and bind to my services.

          – John
          Nov 14 '18 at 5:22


















          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%2f53292669%2fandroid-architecture-components-communication-between-activity-fragment-and-se%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python