title: How to use RxJava or Observables to listen for a variable change in a different class?
body: <p>I am attempting to do a login for an android app. My problem is that when I call login from Activity.java, the Service.java method uses call.enqueue from Retrofit and it is async. So I am not able to wait and consume the response in the Activity.java method (so that I can handle what happens next). </p>
  
  <p>Therefore, I decided that if I can setup a listener of some sort to capture when the response object changes, that I can handle what happens next in the app.</p>
  
  <p>I have been looking into RxJava but no examples that I have seen work across multiple classes or seem to actually work properly. It would be extremely helpful to have some basic syntax that I could apply to this that would allow me to consume the login response object so that I can handle what happens next in the application. I am not married to RxJava either so if there is a different way to approach this that will let me consume this object, I'm fine with that. Thanks!!</p>
  
  <p>GlobalData.java</p>
  
  <pre><code>public class GlobalData {
      public static LoginResponse globalResponse;
  }
  </code></pre>
  
  <p>Activity.java</p>
  
  <pre><code>public class Activity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // Can I subscribe here and do some logic for when globalResponse changes?!?
      } 
  
      public void login() {
          // create login request object
          // ...
  
          // call service method
          LoginResponse response = service.loginMethod(request);
  
          // Can I await the async in loginMethod so that I run logic after the call?
      }
  }
  </code></pre>
  
  <p>Service.java</p>
  
  <pre><code>public class Service implements ServiceInterface {
      @Override
      public loginMethod(LoginRequest request) {
          // Setup Retrofit for api call
          // ...
          Call&lt;LoginResponse&gt; call = apiService.login(request);
  
          // async call to get a response from the api for login
          call.enqueue(new Callback&lt;LoginResponse&gt;() {
              @Override
              public void onResponse(Call&lt;LoginResponse&gt; call, Response&lt;LoginResponse&gt; response) {
                  GlobalData.globalResponse = response.body(); // updates global data variable with the response from login
              }
          }
      }
  }
  </code></pre>