I have written the underlying code to display an activityindicator while a hhtp connection call is made. Unfortunately, the activity indicator does not appear on the screen till the http connection call is complete. Hence it is not serving its purpose.
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH);
ActivityIndicatorModel model = new ActivityIndicatorModel();
ActivityIndicatorController controller = new ActivityIndicatorController();
view.setController(controller);
view.setModel(model);
controller.setModel(model);
controller.setView(view);
model.setController(controller);
Bitmap bitmap = Bitmap.getBitmapResource("spinner.png");
view.createActivityImageField(bitmap, 5, Field.FIELD_HCENTER);
_activityFieldManager.add(view);
UiApplication.getUiApplication().getActiveScreen().invalidate();
}
});
//SyncWithDB is the Class that makes the Http connection call
new SyncWithDB();
_activityFieldManager.delete(view);
UiApplication.getUiApplication().getActiveScreen().invalidate();
Dialog.inform("Sync Complete");
As suggested I even tried
view = new ActivityIndicatorView(Field.USE_ALL_WIDTH);
ActivityIndicatorModel model = new ActivityIndicatorModel();
ActivityIndicatorController controller = new ActivityIndicatorController();
view.setController(controller);
view.setModel(model);
controller.setModel(model);
controller.setView(view);
model.setController(controller);
Bitmap bitmap = Bitmap.getBitmapResource("spinner.png");
view.createActivityImageField(bitmap, 5, Field.FIELD_HCENTER);
_activityFieldManager.add(view);
UiApplication.getUiApplication().getActiveScreen().invalidate();
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
try {
new SyncWithDB();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
_activityFieldManager.delete(view);
UiApplication.getUiApplication().getActiveScreen().invalidate();
Dialog.inform("Sync Complete");
But the result remains the same.
Since you are using invokeAndWait(), are you performing the HTTP operation in a worker thread? If not, you should be. The ActivityIndicator should be managed in the main dispatch thread, and the HTTP operation managed in a worker thread.
For example:
Or, a little more generically: