title: java.lang.IllegalStateException: Not on the main thread
body: <p>I am trying to delete the markers from the Goolge map in the FragmentActivity Map when there is no data available in the table for the makers on the serverside also the data object is empty but I am getting the error below. How can I fix it?</p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>07-12 20:53:05.697: E/AndroidRuntime(26364): FATAL EXCEPTION: IntentService[IntentService]
  07-12 20:53:05.697: E/AndroidRuntime(26364): Process: com.bustracker, PID: 26364
  07-12 20:53:05.697: E/AndroidRuntime(26364): java.lang.IllegalStateException: Not on the main thread
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.l.a.ce.b(Unknown Source)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.maps.api.android.lib6.d.ct.a(Unknown Source)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.maps.api.android.lib6.d.aq.a(Unknown Source)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.android.gms.maps.model.internal.t.onTransact(SourceFile:51)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at android.os.Binder.transact(Binder.java:380)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.android.gms.maps.model.internal.zzi$zza$zza.remove(Unknown Source)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.google.android.gms.maps.model.Marker.remove(Unknown Source)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at com.bustracker.GetLLRD.onHandleIntent(GetLLRD.java:120)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at android.os.Handler.dispatchMessage(Handler.java:102)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at android.os.Looper.loop(Looper.java:145)
  07-12 20:53:05.697: E/AndroidRuntime(26364):    at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p><strong>onHandleIntent method in the GetLLRD IntentService class:</strong></p>
  
  <pre><code>protected void onHandleIntent(Intent intent) {
  
                              if (data != null &amp;&amp; !data.isEmpty()) {
                                  Intent intent1 = new Intent(this, Map.class);
                                  intent1.putExtra("list_data", data);
                                  intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                          | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                                  startActivity(intent1);
  
                              } else if (Map.markerMap != null
                                      &amp;&amp; !Map.markerMap.isEmpty()) {
  
                                  Iterator&lt;HashMap.Entry&lt;Integer, Marker&gt;&gt; it = Map.markerMap
                                          .entrySet().iterator();
                                  while (it.hasNext()) {
                                      HashMap.Entry&lt;Integer, Marker&gt; entery = it
                                              .next();
                                      int key = entery.getKey();
                                      Map.marker = Map.markerMap.get(key);
                                      System.out.println("test marker " + Map.marker ); 
                                      //Line 120.
                                      Map.marker .remove();
                                      Map.markerMap.remove(key);
  
                                      // Marker value = entery.getValue();
                                  }
                              }
  </code></pre>
  
  <p><strong>Map fragmentActivity:</strong></p>
  
  <pre><code>public class Map extends FragmentActivity implements OnMapReadyCallback {
  
      GoogleMap map;
      static HashMap&lt;Integer, Marker&gt; markerMap = new HashMap&lt;Integer, Marker&gt;();
      static Marker marker = null;
  
      ...
      }
  </code></pre>