I get this error -
java.lang.IllegalStateException: The specified message queue synchronization lock token has not been sent or has already been deleted.
As a relative newbie to Java / Android, there is no doubt that I missed, but what I do is
I have a project that uses Exif Data to display photos according to the date they were taken and the intention is to use a similar model at every stage ...
Work topic → User interface → User display adapter. Then clicking on one of the "Cells" in the GridView calls the next action. The first activity searches for all photo files, creating a list of "Years", and then each subsequent activity filters it up to several months, days, etc.
The start of the second action, however, starts directly at the above error, and messages are processed through the basic Thread / Handler setting.
Here is a class that passes messages to a stream -
public class MonthSort {
Handler handler;
int imageWidth;
List<PhotoData> photoList;
public MonthSort(Handler handler2, int width, List<PhotoData> pList) {
photoList = new ArrayList<PhotoData>();
photoList = pList;
imageWidth = width;
handler = handler2;
}
public void sortFiles()
{
int month, photoCount;
File fileName = new File("");
Message msg = handler.obtainMessage();
try {
for (int i = 0; i < 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) {
Log.d("Debug", "handler error occurs in monthSort class");
}
}
... and this is the code that gets it in the user interface thread.
public class MonthActivity extends Activity {
List<PhotoData> photoList;
static List<MonthData> 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();
boolean ended = bundle.getBoolean("end");
if(ended)
{
} 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) {
Log.d("Debug", "handler error occurs in UI Handler");
}
}
}
};
Please note that I did not include all the code, only those parts that I think are relevant.
previous activity managed to successfully manage messages in the same way, why not the second action?
, , . , ?