Hi,
I was wondering if someone could help me with my asynctask? I have a
problem with onPostExecute and onCancelled. onPostExecute seems to be
skipped everytime I run the asynctask, the file downloads, no problem,
but the dialog is still there. As for the cancel button, it doesn't
seem to reach onCancelled. Can anyone wee what I'm doing wrong?

/André

protected class DownloadTask extends AsyncTask<Context, Integer,
Void>{

            private Dialog dialogD;
            private ProgressBar downloadBar;
            private ImageButton cancel;

            OnClickListener listen = new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                if(v == cancel) {
                                        downloadTask.cancel(true);
                                }
                        }
                };

                @Override
                protected void onPreExecute() {
                        super.onPreExecute();
//                      Context mContext = getApplicationContext();
                        dialogD = new Dialog(SilverFTP.this);
                        dialogD.setContentView(R.layout.silver_ftp_downloading);
                        dialogD.setTitle("Downloading...");
                        TextView info = (TextView)
dialogD.findViewById(R.id.download_info);
                        info.setText(fileName);
                        downloadBar = (ProgressBar)
dialogD.findViewById(R.id.download_bar);
                        cancel = (ImageButton) 
dialogD.findViewById(R.id.cancel_download);
                        cancel.setOnClickListener((OnClickListener) this);
                        dialogD.show();
                        logg.append("onPreExecute" + "\n");
                        Log.i("makemachine", "onPreExecute()");
                }

                @Override
                protected Void doInBackground(final Context... params) {
                    try {
                        InputStream stO = new
BufferedInputStream(client.retrieveFileStream(fileToUse),
client.getBufferSize());
                    OutputStream stD = new FileOutputStream(placeToPaste);
                    while (ftpTotal < ftpSize) {
                            Util.copyStream(stO, stD, client.getBufferSize(),
CopyStreamEvent.UNKNOWN_STREAM_SIZE, new CopyStreamAdapter(){
                                    public void bytesTransferred(long
totalBytesTransferred, int bytesTransferred, long streamSize) {
                                        double tempProgress =
(((double)totalBytesTransferred / (double)ftpSize) * 100.0);
                                        int progress = (int) tempProgress;
                                        publishProgress(progress);
                                }
                            });
                    }
                    client.completePendingCommand();
                        } catch (IOException e) {
                                logg.append("Download IOExc, download()" + 
"\n");
                                e.printStackTrace();
                        }
                        return null;
                }

                protected void onProgressUpdate(final Integer... values) {
                        downloadBar.setProgress(values[0]);
                        Log.i("makemachine", "onProgressUpdate(): " +
String.valueOf(values[0]));
                }

                @Override
                protected void onCancelled() {
                        super.onCancelled();
                        downloadTask.dialogD.dismiss();
                }

                @Override
                protected void onPostExecute(Void v) {
                        logg.append("onPostExecute" + "\n");
                        downloadTask.dialogD.dismiss();

                }

    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to