When i'm in onActivityResult and i try to show a custom progress dialog,
The dialog is not show, but the function is called, but nothing is displayed If i put this dialog in Oncreate it's working i see the dialogbox, Is it possible to show a custom dialog on return of Intent.ACTION_GET_CONTENT / MediaStore.ACTION_IMAGE_CAPTUREThanks
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Parseur UploadPhoto = new Parseur();
showDialog(PROGRESS_DIALOG);
if (requestCode == z_const.REQUEST_INTENT_CODE_PHOTO_CHOISIR) {
String selectedImagePath;
Uri selectedImageUri;
if (data != null){
selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Log.e(TAG, "PHOTO CHOISIR " + selectedImagePath+"Res"+resultCode);
UploadPhoto.uploa开发者_运维百科dPhoto(InfoPasse,selectedImagePath);
}
}
finish();
}
protected Dialog onCreateDialog(int id) {
Log.e(TAG," DIAL appeller "+id);
switch(id) {
case PROGRESS_DIALOG:
progressDialog = new ProgressDialog(Photo.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressThread = new ProgressThread(handler);
progressThread.start();
return progressDialog;
default:
return null;
}
}
Anwser :)
- Play the loking task in AsyncTask inside doInBackground
- Start dialog before call intent
So replace the loking task UploadPhoto.uploadPhoto(InfoPasse,selectedImagePath);
by new UploadInBackground().execute(selectedImagePath);
and AsyncTask look like :
private class UploadInBackground extends AsyncTask<String, Integer, Long> {
@Override
protected Long doInBackground(String... params) {
UploadPhoto.uploadPhoto(InfoPasse,params[0]);
return null
}
@Override
protected void onProgressUpdate(Integer... progress) {
}
@Override
protected void onPostExecute(Long result) {
finish();
}
}
精彩评论