I have really been struggling figuring out how to get a ProgressDialog on the UI Thread for this code given that uploadPhoto and would appreciate any guidance:
@Override
/** Handle Upload a Photo **/
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
// Get image
if (resultCode == RESULT_OK) {
// ProgressDialog dialog = ProgressDialog.show(this, "", "Uploading Photo...", true, false);
switch(requestCode) {
// Take Photo
case 4001:
// Upload
uploadPhoto(Uri.fromFile(mImageFile));
break;
// Select Photo
case 5001:
// Get image
Uri selectedImage = imageReturnedIntent.getData();
// Upload
uploadPhoto(selectedImage);
break;
}
// Dismiss
// dialog.dismiss();
}
}
use AsyncTask may be. put the upload photo function in background of the async task.
start a progress dialog in pre execute.
dismiss/cancel progress dialog in post execute.
post execute and pre execute run on UI thread.
to call the asyncTask use