/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class MyThins { private OnProgressListener<FilesNeedDownloadingCheckerTask> onProgressListener; private OnFinishedListener<FilesNeedDownloadingCheckerTask, Result> onFinishedListener; private FilesNeedDownloadingCheckerTask task; public void setOnProgressListener(OnProgressListener<FilesNeedDownloadingCheckerTask> onProgressListener) { this.onProgressListener = onProgressListener; } public void setOnFinishedListener(OnFinishedListener<FilesNeedDownloadingCheckerTask, Result> onFinishedListener) { this.onFinishedListener = onFinishedListener; } super(); this.itemsToProcess = items; } public void cancel() { if (task != null) { task.cancel(true); } } public void runAsync() { task = new MyThingTask(); task.execute(null); } public class Result { public ArrayList<Object> results = new ArrayList<Object>(); } Result result = new Result(); @Override // do things with this.itemsToProcess.. if (isCancelled()) { return null); // return result; } @Override super.onProgressUpdate(values); if (onProgressListener != null) { onProgressListener.onProgress(this, (double)values[0] / (double) remoteFiles.length ); } } @Override protected void onPostExecute(Result result) { super.onPostExecute(result); if (onFinishedListener != null) { onFinishedListener.onFinished(this, result); } } } }