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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:06:07+00:00 2026-06-16T03:06:07+00:00

In my application the system will download images from an url and save it

  • 0

In my application the system will download images from an url and save it into phone memory. (I did not included url address in the question) On top of that, it will also save data into sqlite database. Data that save is file name, filepath and file size. But currently once I go through the download process whether the download complete or fail in the middle of the process, it also will insert into the database.
Is there any way that I can check whether the download process is completed or not?

        GalleryScreen.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                boolean isDownloadResult = false;


                        int NumIncrease = 0;
                        Log.i(TAG, "NumberIncrease:" +NumIncrease);
                        Toast.makeText(getApplicationContext(), "Downloading.............>>>>>>>>>>>", Toast.LENGTH_SHORT).show();
                        Bitmap bm;
                        InputStream in;



                        try{


                            in = new java.net.URL(URL).openStream();
                            bm = BitmapFactory.decodeStream(new PatchInputStream(in));

                            File storage = new File(Environment.getExternalStorageDirectory() + File.separator + "/Images/");
                            Log.i(TAG,"storage:" +storage);
                            Log.i(TAG,"storage:" +storage.getAbsolutePath());
                            if(!storage.exists()){
                                storage.mkdirs();


                            }

                                String FileName = "/"+CONTENT_ID+".jpg"; 
                                FileOutputStream fos = new FileOutputStream(storage + FileName);
                                bm.compress(Bitmap.CompressFormat.JPEG, 85, fos);

                                String filepath = storage + FileName;
                                File filecheck = new File (filepath);
                                long fileSize = filecheck.length();
                                fos.flush();
                                fos.close();

                                Log.i(TAG, "bm:" +bm);
                                Log.i(TAG, "fos:" +fos);
                                Log.i(TAG, "filesize:" +fileSize);
                                Log.i(TAG, "filepath:" +filepath);
                                helper.insert_content(filepath, fileSize, requestTime);


                            isDownload = false;
                        }
                        catch(IOException e1){
                                e1.printStackTrace();
                                }   
            }

        });
  • 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-16T03:06:08+00:00Added an answer on June 16, 2026 at 3:06 am

    Please use AsyncTask. AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

    AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.)

    you can just use an anonymous class for the async task. This would like this:

    ImageView mChart = (ImageView) findViewById(R.id.imageview);
    String URL = "http://www...anything ...";
    
    mChart.setTag(URL);
    new DownloadImageTask.execute(mChart);
    

    The Task class:

    public class DownloadImagesTask extends AsyncTask<ImageView, Void, Bitmap> {
    
    ImageView imageView = null;
    
    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String)imageView.getTag());
    }
    
    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }
    
    
    private Bitmap download_Image(String url) {
       ...
    }
    

    Here, onPostExecute, you can easily check whether the process of download image is completed or not.

    Further reading

    • http://developer.android.com/reference/android/os/AsyncTask.html
    • Loading Image using AsyncTask
    • Android : Loading an image from the Web with Asynctask
    • Android Help with adding a progress dialog while image loading?

    EDIT:

    • If you are trying to download larger files, you might consider
      putting your application into some type of Service as this would
      potentially take a few hours.
    • You can consider using Download Manger for newer devices
      (with Android 2.3+)
    • Also a nice resource ->
      Download a file with Android, and showing the progress in a ProgressDialog
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Java application which will download a HTML page from a website
Please note this application will never be running on a server system. I am
Is it possible to embed a Gtk widget into an application using System.Windows.Forms? Thanks!
I'm developing a Windows Form application that will typically minimize to the system tray.
I Made an application to download a folder from a given sharepoint site, but
I installed jbilling application in my system. download jbilling latest version in jbilling site.
I have content management system application that uses a polymorphic tree table as the
I am adding my application in system tray when I close it. But it
i am creating a big application (ERP system) and i am confused to use
I need to display application settings screen for a specific system application in my

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.