title: Thread/Handler error - The specified message queue synchronization barrier token has not been posted
body: <p>I am getting this error - </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: The specified message queue synchronization  barrier token has not been posted or has already been removed.</p>
  </blockquote>
  
  <p>As a relative newcomer to Java/Android, there is no doubt something I have missed, but what I am doing is this - </p>
  
  <p>I have a project which uses Exif Data to display Photos according to the date they were taken, and the intention is to use a similar model on each stage...</p>
  
  <p>Worker Thread -> UI Thread -> Custom Display Adapter. Then clicking on one of the "Cells" in GridView triggers the next Activity. The First Activity searches for all the Photo Files, creating a list of "Years", and then each subsequent activity filters it to months, days etc. </p>
  
  <p>Starting the second activity however launches straight into the above error, and the Messages are dealt with via the basic Thread/Handler set-up. </p>
  
  <p>Here is the class that is passing the messages to the thread - </p>
  
  <pre><code>public class MonthSort {
  Handler handler;
  int imageWidth;
  List&lt;PhotoData&gt; photoList;
  public MonthSort(Handler handler2, int width, List&lt;PhotoData&gt; pList) {
      photoList = new ArrayList&lt;PhotoData&gt;();
      photoList = pList;
      imageWidth = width;
      handler = handler2;
  }
  
  public void sortFiles()
  {
      int month, photoCount;
      File fileName = new File("");
      Message msg = handler.obtainMessage();
      //Message msg = Message.obtain();
      //Bundle bundle = new Bundle();
      try {
          for (int i = 0; i &lt; 12; i++) {
              month = i + 1;
              photoCount = 0;
              for (PhotoData pd : photoList) {
                  if(month == pd.month)
                  {
                      if(photoCount == 0)
                          fileName = pd.fileName;
                      photoCount++;
                  }
              }
              if(photoCount != 0)
              {
  
                  Bundle bundle = new Bundle();
                  bundle.putString("filename", fileName.toString());
                  bundle.putInt("month", month);
                  bundle.putInt("count", photoCount);
                  byte[] thumbNail = getThumbnail(fileName, imageWidth);
                  bundle.putByteArray("thumbnail", thumbNail);
  
  
                  msg.setData(bundle);
                  handler.sendMessage(msg);
  
              }
          }
      } catch (Exception e) {
          // TODO Auto-generated catch block
          Log.d("Debug", "handler error occurs in monthSort class");
      }
      /*Bundle bundle = new Bundle();
      bundle.putBoolean("end", true);
      msg.setData(bundle);
      handler.sendMessage(msg);*/
  }
  </code></pre>
  
  <p>... and this is the code that receives it in the UI Thread.</p>
  
  <pre><code>public class MonthActivity extends Activity {
  List&lt;PhotoData&gt; photoList;
  static List&lt;MonthData&gt; photos;
  int imageWidth;
  GridView photoGrid;
  static ImageAdapter2 iAdapter;
  int year;
  Thread monthSortThread;
  
  Handler handler2 = new Handler() {
      @Override
      public void handleMessage(Message msg) 
      {
          Bundle bundle = msg.getData();  // Get the message sent to the Handler.
          boolean ended = bundle.getBoolean("end");
          if(ended)
          {
              //Toast.makeText(getBaseContext(), "FINISHED !!!", Toast.LENGTH_LONG).show();
          } else
          {
              try {
                  MonthData md = new MonthData();
                  md.monthValue = bundle.getInt("month");
                  md.monthString = getMonthString(md.monthValue);
                  md.count = bundle.getInt("count");
                  byte[] tn = bundle.getByteArray("thumbnail");
                  md.thumbnail =  BitmapFactory.decodeByteArray(tn, 0, tn.length);
                  photos.add(md);
                  iAdapter.notifyDataSetChanged();
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  Log.d("Debug", "handler error occurs in UI Handler");
              }
          }
      }
  };
  </code></pre>
  
  <p>Please note that I haven't included all of the code, just the parts I feel are relevant. </p>
  
  <p>The previous activity managed to successfully operate messages in the same way, why not the second activity ?</p>
  
  <p>I understand that the Main UI thread already has a looper set-up, and therefore you don't have to create one. Is that still true of any subsequent Activities that are launched ?</p>