title: Android how to update (UI thread) from other classes (really?)
body: <p>you may know about <a href="https://developer.android.com/google/gcm/client.html" rel="nofollow">Google Cloud Messaging</a> </p>
  
  <p>The problem is that when a gcm message triggers by the server, my application receives a bundle from google play services, this happen at <code>GcmBroadcastReceiver.java</code>. Here i can send this data to other classes in order to append some info from the server.. well. I got stuck when i try to update, for example, some views in the UI thread.</p>
  
  <p>HOW I CAN DO THIS?</p>
  
  <p>Imagine that <code>MainActivity.java</code> is the UI thread when i declare the views, etc. </p>
  
  <p>I tried to create here a public static method which can be called directly by <code>GcmBroadcastReceiver.java</code> by this way: <code>MainActivity.*updateUI*(args..)</code>, but it throws this exception:</p>
  
  <pre><code>android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
  </code></pre>
  
  <p>Can anyone try to explain me this? i also know about asyncTask but i cant imagine how it works. I also find some pages explaining events that are fired by the UI thread it self like runnables that do some task in background. Im searching something like this: </p>
  
  <pre><code>MainActivity extends Activity{
  
      ...
      protected void onCreate(Bundle blabla)..{
  
      setContentView(R.layout.blabla);
  
      registerSomeEvent(this);
  
      }
  
      private void handleEvent(Bundle ...){
  
      ... do stuff with the data provided in the UI thread
  
      }
  
  } 
  </code></pre>
  
  <p>And here at <code>GcmBroadcastReceiver</code>, when gcm push some data, trigger that magic event in order to perform updates at the UI thread with some views like <code>ListViews</code> or <code>TextView</code></p>