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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With