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 6759739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:59:09+00:00 2026-05-26T13:59:09+00:00

I have this code that pulls an image from an url and displays it

  • 0

I have this code that pulls an image from an url and displays it within the app.

    Drawable drawableTest = LoadImageFromWeb("http://www.someimageurl");
    imgView.setImageDrawable(drawableTest);

private Drawable LoadImageFromWeb(String url){
    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    }catch (Exception e) {
        System.out.println("Exc="+e);
        return null;
    }
 }

The method works and the image is pulled into the app without a problem. What I’d like to do is two things…

1) Move the process to a background thread.

2) Display a “loading” drawable (located in drawable folder) while the image is being downloaded and then switch to image when done. If there’s a problem I’d like to load a “unable to load image” drawable (also located in drawable folder).

Can someone help modify the method above so that it will run in the background and display the appropriate images upon loading and if there’s a problem?

Thanks! You guys rock btw.

Shannon

  • 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-26T13:59:10+00:00Added an answer on May 26, 2026 at 1:59 pm

    You can use AsyncTask to run the task in another thread. That way, it won’t block UI. Roughly, it should be something like this:

    private class MyTask extends AsyncTask<String, Void, Drawable> {
    
         ProgressDialog pd;
    
         protected Drawable doInBackground(String... url) {
                try {
                    pd = ProgressDialog.show(this, "Working..", "Getting image", true, false);
                    InputStream is = (InputStream) new URL(url[0]).getContent();
                    Drawable d = Drawable.createFromStream(is, "src name");
                    return d;
                } catch (Exception e) {
                    System.out.println("Exception = " + e);
                    return null;
                }
         }
    
         protected void onProgressUpdate(Void... progress) {
         }
    
         protected void onPostExecute(Drawable result) {
             /* Image loaded...*/
             pd.dismiss();
             imgView.setImageDrawable(result);
    
         }
    }
    
    MyTask task = new MyTask();
    task.execute("http://www.someimageurl");
    

    You can change the ProgressDialog with whatever you like…

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

Sidebar

Related Questions

I have this code that fetches some text from a page using BeautifulSoup soup=
So I have this code that takes care of command acknowledgment from remote computers,
I have some code that pulls HTML from an external source: $doc = new
So I have working code that animates a BG image via a plugin. This
I have this code that performs an ajax call and loads the results into
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,

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.