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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:26:04+00:00 2026-06-07T07:26:04+00:00

I am writing this application where I get live images from a tcp connection

  • 0

I am writing this application where I get live images from a tcp connection and I need to display them on an ImageViev.

What I am doing is calling the asynctask inside the button click. but it seem to create a number of background threads.

this is the code for the button click event

    btnLive.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        try
        {
            String name = ((Button)v).getText().toString();
            if(name.equalsIgnoreCase("Live"))
            {
                DataOutputStream dos;
                DataInputStream dis;
                String reply;

                if(config.conn.isConnected())
                {
                    dos = new DataOutputStream(config.conn.getOutputStream());
                    dos.writeBytes("STREAM-LIVE-IMAGES");                                       
                    dos.flush();
                    //dis = new DataInputStream(in);

                    in = config.conn.getInputStream();                      
                    while (true) 
                    {                               
                        new myTask().execute(in);
                    }
                }                   
            }
        }
        catch(Exception ex)
        {
            Log.d("Live Button ", "Exception " + ex.getMessage() );
        }
    }
});

and this the code for the asyncTask

 class myTask extends AsyncTask<InputStream, Integer, Bitmap> {

protected Bitmap doInBackground(InputStream...in) 
{
    Bitmap bmp = null;

    try 
    {
        //Do some none UI stuff here and return a value *result                 
        byte[] rcvPacket = ReadJpegBinaryAndRemoveDelimiter(in[0]);
        bmp = BitmapFactory.decodeByteArray(rcvPacket, 0, rcvPacket.length);
        Log.d("Live Image Streaming ", "Recieved Images: " + rcvPacket.length + " " +  bmp);

    } catch (Exception e) {
        e.printStackTrace();                    
    }
    return bmp;
}
  • 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-07T07:26:06+00:00Added an answer on June 7, 2026 at 7:26 am

    I managed to sort it out with a background thread because asynctask wasnt the right option for my issue.

    So I created a separate background thread and used a post runnable method on the imageview to update the UI.

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

Sidebar

Related Questions

I am writing a GUI application using Django 1.1.1. This is the views.py: from
I'm writing a WPF calculator app. In this application I have TextBox that get
I am writing a JQuery mobile application. In this application, I need to dynamically
I'm writing this question from the standpoint of an ASP.NET application. However I realize
I am writing a service application in Android . In this application, I am
I am writing a .NET 3.5 WPF application in C#. This application needs to
I'm writing an application using DDD techniques. This is my first attempt at a
I am writing application in Linux using C, pthreads and sockets. This will be
I'm writing a silverlight application that resembles a shopping cart system. This app can
I am writing a turbogears2 application. I have a table like this: class Order(DeclarativeBase):

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.