title: How to avoid duplicate GET calls in Android with RXJava and Retrofit?
body: <p>I'm using rxjava and retrofit 2 to handle my apps call requests. I did everything suggested on the internet, but still haven't found any better solution for my case. I have a widget in my Fragment, and when the user clicked the widget it will be opening new activity. This new activity calls <code>ActivityReward.java</code>.</p>
  <p>When the <code>ActivityReward.java</code> is opened, it will make a call to the server to give data requested by the user. Here's a piece of code in my <code>RewardDataImplementation</code>:</p>
  <pre><code>@Override
  public Observable&lt;JsonObject&gt; getRewardLists() {
      return myInterfaceApi
              .getRewardList()
              .compose(new RxSchedulerSwitcher&lt;JsonObject&gt;(ioScheduler, compScheduler));
  }
  </code></pre>
  <p>Here's my Activity will call the API :</p>
  <pre><code>private void reqRewardList(MyConnector paymentConnector) {
          Map&lt;Object, Object&gt; requestParamMap = new HashMap&lt;&gt;();
          requestParamMap.put(
                  MySyncronousRequestConstant.TYPE_KEY,
                  SyncronousRequestConstant.GET_REWARD_LIST_REQUEST
          );
          MyConnector.postSyncronousRequest(requestParamMap);
      }
  </code></pre>
  <p>Here's my myInterfaceApi.java calls:</p>
  <pre><code>@Headers(&quot;Content-Type: application/json&quot;)
  @GET(&quot;/rewardList&quot;)
  Observable&lt;JsonObject&gt; getRewardList();
  </code></pre>
  <p>Everything works fine whether the body is empty or filled, but I saw this on my log, the response becomes duplicates, like every time I opened the <code>ActivityReward.java</code>, the requests will call the server like twice, I don't want this to happen:</p>
  <pre><code>2021-06-30 15:54:41.083 31580-11282/com.example.myproject D/Retrofit: ---&gt; HTTP GET https://localhost/rewardList
  2021-06-30 15:54:41.083 31580-11282/com.example.myproject D/Retrofit: Accept: application/json
  2021-06-30 15:54:41.083 31580-11282/com.example.myproject D/Retrofit: Content-Type: application/json
  2021-06-30 15:54:41.083 31580-11282/com.example.myproject D/Retrofit: ---&gt; END HTTP (no body)
  2021-06-30 15:54:41.089 31580-11283/com.example.myproject D/Retrofit: ---&gt; HTTP GET https://localhost/rewardList
  2021-06-30 15:54:41.089 31580-11283/com.example.myproject D/Retrofit: Accept: application/json
  2021-06-30 15:54:41.089 31580-11283/com.example.myproject D/Retrofit: Content-Type: application/json
  2021-06-30 15:54:41.089 31580-11283/com.example.myproject D/Retrofit: ---&gt; END HTTP (no body)
  </code></pre>
  <p>Is there any proper solution for my case? I want it when the user opens the <code>ActivityReward.java</code>, the API will only call the server once and <strong>NOT</strong> twice.</p>