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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:51:01+00:00 2026-06-13T18:51:01+00:00

Below is my Async class public class GetBitMapFromURL extends AsyncTask<String, Integer, String> { byte[]

  • 0

Below is my Async class

public class GetBitMapFromURL   extends AsyncTask<String, Integer, String>
{
    byte[] tempByte;
    private Bitmap bmap;
@Override
    protected String doInBackground(String... params) 
    {
        // TODO Auto-generated method stub
        String stringUrl = params[0];
        //bmap = null;
        try 
        {
            URL url = new URL(stringUrl);
            InputStream is = (InputStream) url.getContent();
            byte[] buffer = new byte[8192];
            int bytesRead;
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            while ((bytesRead = is.read(buffer)) != -1) 
            {
                output.write(buffer, 0, bytesRead);
            }
            tempByte = output.toByteArray();
        }
        catch (MalformedURLException e) 
        {
            e.printStackTrace();

        } 
        catch (IOException e) 
        {
            e.printStackTrace();

        }
        return "Success";
    }

    @Override
    protected void onPostExecute(String result) 
    {
        super.onPostExecute(result);
        Bitmap tempBitMap = BitmapFactory.decodeByteArray(tempByte, 0, tempByte.length);
        //Log.d("Bitmap bmap value on PostExecute", "bmap="+bmap);
        setBitMap(tempBitMap);
        //imageView.setImageBitmap(bImg);
    }
    void setBitMap(Bitmap bitMapSet)
    {
        this.bmap  = bitMapSet;
        //Log.d("Bitmap bmap value", "bmap="+bmap);
    }
    Bitmap returnBitmap()
    {
        //Log.d("Bitmap bmap value", "bmap="+bmap);
        return bmap;
    }

}

In spite of doing the following in my activity, the returnBitMap() returns null.

GetBitMapFromURL gbmap1 = new GetBitMapFromURL();       //Obtain medium bitmap
    gbmap1.execute(applicationImageMediumURL);
    if(gbmap1.getStatus() == AsyncTask.Status.FINISHED)
    {
        applicationMediumBitMap = gbmap1.returnBitmap();
     }

Suggest me as to where I’m going wrong.

  • 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-13T18:51:03+00:00Added an answer on June 13, 2026 at 6:51 pm

    Don’t do that, use the AsyncTask.onPostExecute() method to update the UI like

    @Override
    protected void onPostExecute(String result) 
    {
        super.onPostExecute(result);
        applicationMediumBitMap  = BitmapFactory.decodeByteArray(tempByte, 0, tempByte.length);
        //Log.d("Bitmap bmap value on PostExecute", "bmap="+bmap);
    
       // call any method on the activity to continue the process..
       otherStuff();
    }
    

    and remove the code

      if(gbmap1.getStatus() == AsyncTask.Status.FINISHED)
       {
            applicationMediumBitMap = gbmap1.returnBitmap();
        }
    
       // other stuff code
    

    in the Activity onCreate() (I guess). Put any following code to this on its own Activity method and call it within onPostExecute().

    private void otherStuff() {
       // other stuff code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does async JMS work? I've below sample code: public class JmsAdapter implements MessageListener,
Let's say I have an async controller like that below ~ public class HomeController
I have two async classes in my application which you can see below class
I created a server hub in an asp.net application like below public class Calc
I have the below class I want to unit test: public class MyClass {
How do I implement an async method in Python DBus? An Example below: class
I have to perform async execution, and i have wrote the below code var
Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
i am downloading data from website using asynctask and my code for async task
How do i update listivew when async task is done. Below is the sample

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.