Another Android puzzler. Sure someone has an answer, but I can't figure it out. Here's the scenario and then I will show some code...
I have a list of data (call them "Forms") I want to submit to our servers. Each of these "Forms" can have media associated with them, the task is syncPendingFormsResultTask. On top of that, sometimes as I am submitting the "Form" I may have to prompt the user for more information before submitting it. That prompting requires me to get more info, right at that moment, from the server...another AsyncTask call, workflowTask.
My problem is showing progress and also gathering the data. The tendency is for the Dialogs prompting for more data to display last and for no progress dialog information to be shown. It works fine for a single instance, so I know it must be AsyncTask related (not the first time there!).
The logic is something like this:
Loop forms
if (more data)
AsyncTask get more data (synchronous using .get())
Dialog to prompt user with data from AsyncTask
AsyncTask to submit gathered data, show progress progress of media
being sent to server
else
AsyncTask to submit gathered data, show progress of media being sent to
server
Please note that in the onClick in the promptUserForWorkflowInfo the same AsyncTask syncPendingFormsResultTask to submit data is called. I have tried to make the syncPendingFormsResultTask synchronous (using execute().get()) without success.
Bottom line is that I would like this all to really be synchronous and to display the progress...for example with 3 "Forms" and 1 needing extra data it would:
Form 1 (no data needed)...sending 1 of 3 media
Form 1 (no data needed)...sending 2 of 3 media
Form 1 (no data needed)...sending 3 of 3 media
Form 2 - Getting extra data from server...
Form 2 - Prompt user for more data
Form 2 (extra data) ...sending 1 of 3 media
Form 2 (extra data)...sending 2 of 3 media
Form 2 (extra data)...sending 3 of 3 media
Form 3 (no data needed)...sending 1 of 3 media
Form 3 (no data needed)...sending 2 of 3 media
Form 3 (no data needed)...sending 3 of 3 media
Everything does seem to submit fine, just not getting progress or prompting for data in order shown.
Code:
Integer cnt = 1;
Integer size = pendingForms.size();
for (FormSimple pendingForm : pendingForms) {
Form form = libraryUtils.retrieveFormInstanceForm(pendingForm.getInstanceId());
if (form.getWorkflow() != null) {
// before we submit, check to see if we need to get workflow info
ArrayList<WorkflowInfo> workflowinfo = null;
try {
workflowinfo = new workflowTask().execute(form).get();
promptUserForWorkflowInfo(getActivity(), form, workflowinfo, size, cnt);
}
catch (Exception ex) {
Utilities.logException(ex);
}
}
// Just submit
else {
new syncPendingFormsResultTask().execute(form, size, cnt);
}
// Increment count
cnt++;
}
Finally, I have also tried to
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire