title: How to check whether the process of download image is completed or not?
body: <p>In my application the system will download images from an url and save it into phone memory. <em>(I did not included url address in the question)</em> 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.<br>
  Is there any way that I can check whether the download process is completed or not?</p>
  
  <pre><code>        GalleryScreen.this.runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  boolean isDownloadResult = false;
  
  
                          int NumIncrease = 0;
                          Log.i(TAG, "NumberIncrease:" +NumIncrease);
                          Toast.makeText(getApplicationContext(), "Downloading.............&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;", 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();
                                  }   
              }
  
          });
  </code></pre>