Wie, um wieder die Aufgabe Abschlussstatus in AsyncTask

Dies ist im Zusammenhang zu meinem vorherigen post Problem mit dem herunterladen mehrerer Dateien mit AsyncTask

Ich versuche, die download-zwei video-Dateien, und zeigen auch ein ProgressDialog während des Prozesses. Für diese bin ich mit AsyncTask. Ich will den 1. download abgeschlossen, Speicher freizugeben starten Sie dann den 2. download. Ich schrieb Sie den folgenden code, um dies zu erreichen, aber es scheint, der 2. download beginnt nie.

startDownload() {
   DownloadFileAsync d1 = new DownloadFileAsync();
   d1.execute(videoPath+fileNames[0],fileNames[0]);

   if(d1.getStatus()==AsyncTask.Status.FINISHED) {
     d1 = null;
     DownloadFileAsync d2 = new DownloadFileAsync();
     d2.execute(videoPath+fileNames[1],fileNames[1]);
   }
}

Gibt es eine Möglichkeit, dass ich wieder den status meiner 1. Aufgabe & starten Sie dann den 2.?

Die folgenden ist der code von meinem DownloadFileAsync Klasse:

class DownloadFileAsync extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        showDialog(DIALOG_DOWNLOAD_PROGRESS);
    }

    @Override
    protected String doInBackground(String... aurl) {
        int count;

        try {
            URL url = new URL(aurl[0]);
            URLConnection conexion = url.openConnection();
            conexion.connect();

            File root = android.os.Environment.getExternalStorageDirectory();

            int lenghtOfFile = conexion.getContentLength();
            Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream(root.getAbsolutePath() + "/videos/" + aurl[1]);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                output.write(data, 0, count);                    
            }
            output.flush();
            output.close();                
            input.close();

        } catch (Exception e) {}
        return null;

    }
    protected void onProgressUpdate(String... progress) {
         Log.d("ANDRO_ASYNC",progress[0]);
         mProgressDialog.setProgress(Integer.parseInt(progress[0]));
    }

    @Override
    protected void onPostExecute(String unused) {
        dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        tv.append("\n\nFile Download Completed!");
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));            
    }
}
InformationsquelleAutor Sourav | 2011-02-24
Schreibe einen Kommentar