I am working on a project where I download from a file from the web, it is not big only some KBs.
My layout is a list with a label below it. When the user updates (checks if new file is available) I want to replace the label with the activity indicator.
I download the file in a separate thread to not block the main thread. But I have problems with the activity indicator. I use UiApplication.getUiApplication().invokeLater(//CODE);
to remove the label from the manager and add the activity indicator, as well as starting it. Is this correct? I do it in the file downloading thread, and isnt it right that you need to invoke GUI code from the main thread?
then I have block of code (all of this is inside the run method of the file downloading thread) which downloads the report then I have a new invokeLater
method which removes the activity indicator and adds the label again.
However this does not work as expected since the last invokeLater code is run before the first one. I have tested with dialogs. How could I solve this?
I want it to run the code in the order in I coded it in, and no code run before the other ends. How could I accomplish that?
(and yes, I know this is messy!)
private class UpdateReportThread extends Thread {
public void run() {
super.run();
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
view = new ActivityIndicatorView(Field.FIELD_HCENTER);
model = new ActivityIndicatorModel();
controller = new ActivityIndicatorController();
view.setController(controller);
view.setModel(model);
controller.setModel(model);
controller.setView(view);
model.setController(controller);
Bitmap bitmap = Bitmap.getBitmapResource("spinner.jpg");
view.createActivityImageField(bitmap, 5, Field.FIELD_HCENTER);
dialogManager = new VerticalFieldManager(Manager.FIELD_HCENTER | Manager.FIELD_VCENTER | Manager.USE_ALL_HEIGHT);
dialogManager.add(new LabelField("Please wait...", Field.FIELD_HCENTER));
dialogManager.add(view);
add(dialogManager);
view.getModel().resume();
delete(lblIssueWeek);
delete(lblIssueYear);
}
});
//File downloading code
//File downloading code
//File downloading code
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
view.getModel().cancel();
delete(dialogManager);
lblIssueWeek = new LabelField("", LabelField.FIELD_HCENTER);
lblIssueYear = new LabelField("", LabelField.FIELD_HCENTER);
add(lblIssueWeek);
add(lblIssueYear);
updateCurrentIssue();
}
});
}
}