0
    private void copyFile(AppDB apkfile) {
    ProgressDialog pd=new ProgressDialog(this,ProgressDialog.STYLE_SPINNER);
    pd.show(this,"Coping ...",apkfile.name,true,true);
    File f1 = new File(apkfile.location);
    try {
        String fileName = apkfile.name;
        File f2 = new File(Environment.getExternalStorageDirectory().toString() + "/" + "Easy Share");
        f2.mkdirs();
        f2 = new File(f2.getPath() + "/" + fileName + ".apk");
        f2.createNewFile();
        InputStream in = new FileInputStream(f1);
        OutputStream out = new FileOutputStream(f2);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (FileNotFoundException ex) {
        Toast.makeText(this, ex.getMessage() + " in the specified directory.", Toast.LENGTH_SHORT);

    } catch (IOException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
    }
    if(pd.isShowing()) {
   pd.dismiss();}

}

Hi everyone when trying to dismiss the progress dialog it wont do that and serarched for many solution but i not its same Problem. please help.

Update: there is Progress Dialog pd's class after running.

Screenshot 1

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
Omar
  • 17
  • 6

3 Answers3

1

The copy should be done in a Thread or a AsyncTask. Show the dialog before executing the AsyncTask and hide in the onPOstExecute

protected void onPostExecute(Long result) {
       if(mProgressDialog.isShowing()) {
          mProgressDialog.dismiss();}
       }  
}
Damien Praca
  • 3,126
  • 21
  • 14
  • Thanks Man i finally solved it With AsyncTask. I used this Tutorial http://stackoverflow.com/questions/25647881/android-asynctask-example-and-explanation – Omar Mar 09 '16 at 10:39
0

Try with finally

private void copyFile(AppDB apkfile) {
    ProgressDialog pd=new ProgressDialog(this,ProgressDialog.STYLE_SPINNER);
    pd.show(this,"Coping ...",apkfile.name,true,true);
    File f1 = new File(apkfile.location);
    try {
        String fileName = apkfile.name;
        File f2 = new File(Environment.getExternalStorageDirectory().toString() + "/" + "Easy Share");
        f2.mkdirs();
        f2 = new File(f2.getPath() + "/" + fileName + ".apk");
        f2.createNewFile();
        InputStream in = new FileInputStream(f1);
        OutputStream out = new FileOutputStream(f2);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (FileNotFoundException ex) {
        Toast.makeText(this, ex.getMessage() + " in the specified directory.", Toast.LENGTH_SHORT);

    } catch (IOException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
    } finally {
      if(pd.isShowing()) {
        pd.dismiss();
      }
    }
}
User
  • 4,023
  • 4
  • 37
  • 63
0

it is working well i will tell you two possibilities

  1. please use it in try block at last as

    try {
        String fileName = apkfile.name;
        File f2 = new File(Environment.getExternalStorageDirectory().toString() + "/" + "Easy Share");
        f2.mkdirs();
        f2 = new File(f2.getPath() + "/" + fileName + ".apk");
        f2.createNewFile();
        InputStream in = new FileInputStream(f1);
        OutputStream out = new FileOutputStream(f2);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
       if(pd.isShowing()) {
       pd.dismiss();}
        } catch (FileNotFoundException ex) {
            Toast.makeText(this, ex.getMessage() + " in the specified directory.", Toast.LENGTH_SHORT);
       } catch (IOException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
    }
    

    }

second is use in delay

Nisar Ahmad
  • 170
  • 1
  • 7