Progress Dialog not show on onActivityResult function
Asked Answered
V

4

7

I have been developing application on that I got two activity.
first Activity Called Second to get Download url.

In OnActivityResult function of first Activity.there is a ProgressDialog that shows that status of image downloading using that url.

Problem is progress dialog not been shown in that activiy.

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, Kariyachan

Village answered 4/4, 2011 at 9:5 Comment(0)
S
6

You should not execute long-running tasks (i.e. image fetching over network) on the main thread as this blocks UI redrawing.

Use AsyncTask to execute long-running tasks in the background and at the same time update the UI.

Spermatogonium answered 4/4, 2011 at 9:24 Comment(1)
Yeah! .whole screen blank for some time then it show the downloaded Image. Iam going to that with AsyncTask .Thanks for your time-:).Village
M
2

If your WebService class downloads asynchronously, then the dismiss is called just after the show, so your progress dialog appears and disappears at the same time.

If your Webservice class download synchronously then it can cause ANR and your activity might be killed by the system. You have to use it inside another thread by using AsyncTask e.g.

Moa answered 4/4, 2011 at 9:23 Comment(0)
L
0

start a new thread

verlauf = ProgressDialog.show(ctx, "Infrarotauslesung", "initialisiere Bluetooth",true,false);
    new Thread(){
         @Override
        public void run(){ 
                         Looper.prepare();
        }.start();
Loralyn answered 4/4, 2011 at 9:15 Comment(0)
K
0

I think that ProgressDialog has been being shown for a very short time. You should show it before you start Activity with request code CharacterSelector.GetFaceBookImage.

Kamikamikaze answered 4/4, 2011 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.