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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:28:45+00:00 2026-06-05T12:28:45+00:00

My question concerns this thread- How to refresh imageview in android Im too trying

  • 0

My question concerns this thread-
How to refresh imageview in android

Im too trying to get an image via socket, decode it, and setting it on an imageview.
The socket need to stay open in case another image will be sent and then ill update the imageview again.

I didnt got the part when in the other thread they response not to do it in the main thread.

From the main activity I should open a new thread which will be ‘stuck’ on “while (true)”
so it can keep listening to up coming images, and when ever a full image had sent, it needs to update the imageview.
But the imageview is in the main thread (main thread equals UI thread?) so its starting to be a bit problematic for me…

Any one?

// ADDED –
this is the asyncTask I had –

public class AsyncTask extends AsyncTask<Void, Void, Void> {
 private DataInputStream dataInputStream = null;
 private ImageView iv = null;

 public RobotMapAsyncTask(DataInputStream dataStream, ImageView imageView) {
     dataInputStream = dataStream;
     iv = imageView;
 }

@Override
protected Void doInBackground(Void... params) {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    byte[] byteChunk = new byte[1024];
    Bitmap bitmap = null;
    int c;

    if (dataInputStream != null) {
        while (true) {
            try {
                byteChunk = new byte[1024];
                while ((c = dataInputStream.read(byteChunk)) != -1){
                    buffer.write(byteChunk, 0, c);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            bitmap = BitmapFactory.decodeByteArray(byteChunk, 0, byteChunk.length);

            if (bitmap != null) {
                //runOnUiThread(new Runnable() {
                    //public void run() {
                        //iv.setImageBitmap(bitmap);
                    //}
               // }); 
            }
        }
    }

    return null;
}

but then I obvious cant call runOnUiThread because this is not an activity…

  • 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-06-05T12:28:47+00:00Added an answer on June 5, 2026 at 12:28 pm

    Change the image of your ImageView in a Runnable launched by Activity.runOnUIThread(Runnable) or Handler.post(Runnable)

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

Sidebar

Related Questions

This question concerns memory in Android. My method: I have two activites, A and
This question concerns a Tomcat 7 web application, which is connected to a MySQL
This question concerns running python files in terminal that are not stored in the
I am using Sqlite3 with Flask microframework, but this question concerns only the Sqlite
This question concerns the reflection mechanisms of the java programming language. I have an
An interesting thread came up when I typed in this question just now. I
My question is similar to this thread which says to lock the iPhone in
This question concerns generics and types as well as datatables. The following snippet is
I am aware of this question , but I believe my concerns are very
Though this thread recommends using it, I've few concerns: I started with Zend Framework

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.