Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:57:56+00:00 2026-05-24T15:57:56+00:00

i have this class: public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageFromWeb ifw;

  • 0

i have this class:

public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {

ImageFromWeb ifw;
private String url;
private final WeakReference<ImageView> imageViewReference;

public DownloadImageTask(ImageView imageView) {
    imageViewReference = new WeakReference<ImageView>(imageView);
}

@Override
protected Bitmap doInBackground(String... params) {
    url = params[0];
    try {
        return BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

@Override
protected void onPostExecute(Bitmap result) {
    if (isCancelled()) {
        result = null;
    }
    if (imageViewReference != null) {
        ImageView imageView = imageViewReference.get();
        if (imageView != null) {
            imageView.setImageBitmap(result);
        }
    }
}

@Override
protected void onPreExecute() {
    if (imageViewReference != null) {
        ImageView imageView = imageViewReference.get();
        if (imageView != null) {
 ---------> imageView.setImageResource(R.drawable.pw);     
        }
    }
}

}

and the main activity:

public class ImageFromWeb extends Activity {

private String path = "http://....";
private ImageView imageView;

public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.main);

    ImageView mChart = (ImageView) findViewById(R.id.imview);

    mChart.setTag(path);
    new DownloadImageTask(mChart).execute(path);
}

}

I want to put in the point of arrow(in DownloadImageTask class) an alert dialog! How can i do this? Because this class isn’t an activity.

thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:57:57+00:00Added an answer on May 24, 2026 at 3:57 pm

    change the constructor and pass a Context object

    Context mContext;
    public DownloadImageTask(ImageView imageView,Context mContext) {
        imageViewReference = new WeakReference<ImageView>(imageView);
        this.mContext = mContext;
    }
    

    Now you can use this Context to create dialogs

    You can even cast mContext to your Activity class and call functions within your Activity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class: public class Test { public static void main(String[] args) {
I have this class: public class UploadFile : INotifyPropertyChanged { private string name; public
So, I have this class: public class Product { private String name, id, info
I have this simple class: public class LuceneUtil{ private final EntityManager entityManager; public LuceneUtil()
I have this class Entry... public class Entry <K, V> { private final K
I have this class called Table: class Table { public string Name { get
I have some classes layed out like this class A { public virtual void
I have a class which looks something like this: public class Test { private
I have this class public class Address:Entity { public virtual string Address1 { get;
I have this class: public class StatInfo { public string contact; public DateTime date;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.