开发者

Progress Dialog not show on onActivityResult function

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(mybitmap开发者_C百科Drawable.mutate());
                            progressDialog.dismiss();
                            bitmap=null;
                        }
                        catch (IOException e)
                        {
                            //Show server Error message:
                            e.printStackTrace();
                        }

                        break;

Regards, Kariyachan


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.


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.


start a new thread

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜