title: How to implement an Variable Change Listener, for a variable running in different thread (example)
body: <p>I have a AtomicInteger Variable (CurrentCycle) that is being updated in a separate thread to my UI thread. I am trying to update a text field in the UI field based on the the value of the AtomicInteger without an ugle while loop in the UI thread.</p>
  
  <p>I've spent days searching online looking at related queries but am not getting anywhere on this. I'm looking for the simplest way to do this possible. I'm aware that there are posts out there for similar questions but I haven't been able to use them as they have been too abstract or for a different need.</p>
  
  <p>My main questions are:
  1. Do I need to register a listener to do this or is there a simpler way?
  2. Where and how do I register the listener? Do I have to setup a separate interface class (I'd like to avoid this if possible).
  3. Could you please some real example I could use - abstract explanations aren't helping me so far!</p>
  
  <p>I've included my key code (which is not doing anything as the method is not being fired yet) below.  Anyhelp you can provide would be greatly appreciated.</p>
  
  <hr>
  
  <pre><code>// MyActivity.java
      // Declaration (do I need this?)
          AtomicInteger CurrentCycle = new AtomicInteger(0);'
  
  
  // Method which doesn't appear to be firing when CurrentCycle Changes...
      public void setVariableChangeListener(VariableChangeListener variableChangeListener) {
           this.variableChangeListener = variableChangeListener;
  
          if ((CurrentCycle != PreviousCycle ) &amp;&amp; (this.variableChangeListener !=null)) {
              Toast.makeText(getApplicationContext(), "Test - code on variable change is firing.", Toast.LENGTH_SHORT).show();
             PreviousCycle=CurrentCycle;
      }
  </code></pre>