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

  • SEARCH
  • Home
  • 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 have to download an image from a url and then show the downloaded
I need to download an image from internet inside oncreate method of second activity
I need to download an image from some URL to my server. However, my
I need to download images from a website, and I have the login name
All I need to do is download some basic text-based and image files from
I need to download all images from a website to which I have username
I need to send an image (as a downloadable file) from an ASP web
I need to download an image from the web and display it in an
I need to download some images from the Internet and right now I'm using
I have to download an image from the server but I do not wish

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.