Progress dialog not displayed in onActivityResult function

I am developing an application on the basis of two actions.
the first activity is called the second to get the download url.

The OnActivityResult function is the first Activity.there is a ProgressDialog which indicates the status of the image loading using this URL.

The problem is that the progress dialog is not displayed in this activity.

 protected void onActivityResult(int requestCode, int resultCode, Intent imagePicked) { super.onActivityResult(requestCode, resultCode, imagePicked); if(resultCode==RESULT_OK) { ProgressDialog progressDialog=ProgressDialog.show(this, "", "Loading Image"); switch(requestCode) { case CharacterSelector.GetFaceBookImage: //Toast.makeText(this, "onFacebookimageresult", Toast.LENGTH_SHORT).show(); String ImageUrl=imagePicked.getStringExtra("DownloadLink"); WebService getImage=new WebService(ImageUrl); Log.d("Selected Img url", ""+ImageUrl); InputStream inputStream; try { inputStream = getImage.getHttpStream(ImageUrl); getImage=null; Bitmap bitmap=BitmapFactory.decodeStream(inputStream); inputStream=null; mybitmapDrawable=new BitmapDrawable(bitmap); addImageUserImage(mybitmapDrawable.mutate()); progressDialog.dismiss(); bitmap=null; } catch (IOException e) { //Show server Error message: e.printStackTrace(); } break; 

Regards, Karyachan

+4
source share
4 answers

You should not perform lengthy tasks (such as retrieving images over a network) in the main thread, as this blocks the redrawing of the user interface.

Use AsyncTask to perform long-running tasks in the background while updating the user interface.

+4
source

If your WebService class is loaded asynchronously, then the dismissal is called immediately after the show, so the progress dialog appears and disappears at the same time.

If your Webservice class loads synchronously, this could lead to ANR and your activity being killed by the system. You should use it inside another thread using AsyncTask for example.

+2
source

Start new thread

 verlauf = ProgressDialog.show(ctx, "Infrarotauslesung", "initialisiere Bluetooth",true,false); new Thread(){ @Override public void run(){ Looper.prepare(); }.start(); 
0
source

I think the ProgressDialog showing a very short time. You must show it before starting the Activity with the request code CharacterSelector.GetFaceBookImage .

0
source

Source: https://habr.com/ru/post/1346529/


All Articles