开发者

Android : showDialog not displayer inside onActivityResult after take photo

开发者 https://www.devze.com 2023-01-03 00:26 出处:网络
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

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_CAPTURE

Thanks

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 :)

  1. Play the loking task in AsyncTask inside doInBackground
  2. 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();
}

}

0

精彩评论

暂无评论...
验证码 换一张
取 消