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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:16:13+00:00 2026-06-13T10:16:13+00:00

im fetching an image from internet using the below code using an Async task,But

  • 0

im fetching an image from internet using the below code using an Async task,But the bitmp returns from the function is always null.

private Bitmap asyncTaskFetchImage(final String imgeurl) {
        // TODO Auto-generated method stub

        new AsyncTask<Object, Object, Object>() {

            @Override
            protected void onPreExecute() {

                progress_Dialog = ProgressDialog.show(this, "", "Loading");
            }

            @Override
            protected Object doInBackground(Object... params) {
                // TODO Auto-generated method stub
                try
                {
                toSendBg=LoadImageFromURL(imgeurl);
                System.gc();
                return 0;
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
                return 0;
            }
            @Override
            protected void onPostExecute(Object result) {
                if (progress_Dialog != null) {

                    progress_Dialog.dismiss();

                }

            }

        }.execute();
        return toSendBg;
    }

Is this the exact way to return value from an Asyntask?

  • 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-13T10:16:15+00:00Added an answer on June 13, 2026 at 10:16 am

    Try below code to download image from web using AsyncTask and display in imageview.

    public class MainActivity extends Activity {
    
        ImageView mImgView1;
        static Bitmap bm;
        ProgressDialog pd;
        String imageUrl = "https://www.morroccomethod.com/components/com_virtuemart/shop_image/category/resized/Trial_Sizes_4e4ac3b0d3491_175x175.jpg";
        BitmapFactory.Options bmOptions;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mImgView1 = (ImageView) findViewById(R.id.mImgView1);
            pd = ProgressDialog.show(MainActivity.this, "Aguarde...",
                    "Carregando...");
            new ImageDownload().execute("");
        }
    
        public class ImageDownload extends AsyncTask<String, Void, String> {
    
            protected String doInBackground(String... params) {
                // TODO Auto-generated method stub
                bmOptions = new BitmapFactory.Options();
                bmOptions.inSampleSize = 1;
                loadBitmap(imageUrl, bmOptions);
                return imageUrl;
            }
    
            protected void onPostExecute(String imageUrl) {
                pd.dismiss();
                if (!imageUrl.equals("")) {
                    mImgView1.setImageBitmap(bm);
                } else {
                    Toast.makeText(MainActivity.this,
                            "Não foi possível obter resultados", Toast.LENGTH_LONG)
                            .show();
                }
            }
    
        }
    
        public static Bitmap loadBitmap(String URL, BitmapFactory.Options options) {
            InputStream in = null;
            try {
                in = OpenHttpConnection(URL);
                bm = BitmapFactory.decodeStream(in, null, options);
                in.close();
            } catch (IOException e1) {
            }
            return bm;
        }
    
        private static InputStream OpenHttpConnection(String strURL)
                throws IOException {
            InputStream inputStream = null;
            URL url = new URL(strURL);
            URLConnection conn = url.openConnection();
    
            try {
                HttpURLConnection httpConn = (HttpURLConnection) conn;
                httpConn.setRequestMethod("GET");
                httpConn.connect();
    
                if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    inputStream = httpConn.getInputStream();
                }
            } catch (Exception ex) {
            }
            return inputStream;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ZbarSdk for QR Codes, but it is fetching image from camera,
I used the code below to fetch the image from a url but it
I'm fetching some data from an MSSQL table using the mssql_fetch_object, but the text
I am using a image gallery in WordPress, images are fetching from database and
I am fetching Uri of a image from gallery using Intent intent = new
I am fetching some data from a site using its API-key and some other
I am fetching some values in a forEach clause data.forEach(function(content){ ... controller.setAttribute(value from data);
I have a UIViewController and in that controller, i am fetching an image from
I am fetching Image and Text for GridView from a webservice, so its takes
Hi i am getting the following exception while fetching the image from server. I

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.