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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:03:34+00:00 2026-05-15T07:03:34+00:00

I need to download an image from the internet, in a different thread, and

  • 0

I need to download an image from the internet,
in a different thread,
and then send that image object in the handler message, to the UI thread.

I already have this:

...
Message msg = Message.obtain();

Bundle b = new Bundle();
b.putParcelable("MyObject", (Parcelable) object);
msg.setData(b);

handler.sendMessage(msg);

And when I receive this message,
I want to extract the object:

...
public void handleMessage(Message msg) {
    super.handleMessage(msg);

    MyObject objectRcvd = (MyObject) msg.getData().getParcelable("IpTile");
    addToCache(ipTile);
    mapView.invalidate();
}

But this is giving me:

...java.lang.ClassCastException...

Can anyone help?

And by the way, is this the most efficient way
to pass an object to the UI Thread?

Thank you all!

  • 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-15T07:03:35+00:00Added an answer on May 15, 2026 at 7:03 am

    I would use an AsyncTask for this kind of operation. It allows you to hook into your ui thread for things like progress updates and once you have finished your download. The example below shows how one should be done:

    class GetImageTask extends AsyncTask<String, int[], Bitmap> {
    
      @Override
      protected Bitmap doInBackground(String... params) {
        Bitmap bitmap = null;
    
        // Anything done here is in a seperate thread to the UI thread 
        // Do you download from here
    
        // If you want to update the progress you can call
        publishProgress(int progress); // This passes to the onProgressUpdate method
    
        return bitmap; // This passes the bitmap to the onPostExecute method
      }
    
      @Override
      protected void onProgressUpdate(Integer... progress) {
        // This is on your UI thread, useful if you have a progressbar in your view
      }
    
      @Override
      protected void onPostExecute(Bitmap bitmapResult) {
        super.onPostExecute(bitmapResult);
        // This is back on your UI thread - Add your image to your view
        myImageView.setImageBitmap(bitmapResult);
      }
    }
    

    Hope that helps

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

Sidebar

Related Questions

I need customers to be able to download PDFs of letters that have been
I have a need to allow for a user to download an event that
I've download an image from the Internet and converted to a String (This is
I need to download an image from some URL to my server. However, my
I am have an app I am writing that will need to download alot
How to download an image from the web and display it in an UIImageView?
I've been looking for a way to download an image from a URL, preform
How can I copy or duplicate the bitmapdata from a mx:image component? I need
I'm trying to download a PNG image from a Flash application using a Java
I need to periodically download, extract and save the contents of http://data.dot.state.mn.us/dds/det_sample.xml.gz to disk.

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.