Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. /////// $$$$$$$$$$$ SYNTAX
  2. //...
  3.  
  4. new AsyncTask<Void, Void, String>() {
  5. @Override
  6. protected void onPreExecute() {
  7. //...
  8. }
  9.  
  10. @Override
  11. protected String doInBackground(Void... voids) {
  12. return performBlockingTask();
  13. }
  14.  
  15. @Override
  16. protected void onProgressUpdate(Integer... progress) {
  17. mProgessBar.setProgress(progress);
  18. }
  19.  
  20. @Override
  21. protected void onPostExecute(String result) {
  22. mTextView.setText(result);
  23. }
  24.  
  25. }.execute();
  26.  
  27. //...
  28.  
  29. // WORKING EXAMPLE
  30.  
  31. new AsyncTask<URL, Integer, Long>() {
  32. protected Long doInBackground(URL... urls) {
  33. int count = urls.length;
  34. long totalSize = 0;
  35. for (int i = 0; i < count; i++) {
  36. totalSize += Downloader.downloadFile(urls[i]);
  37. publishProgress((int) ((i / (float) count) * 100));
  38. // Escape early if cancel() is called
  39. if (isCancelled()) break;
  40. }
  41. return totalSize;
  42. }
  43.  
  44. protected void onProgressUpdate(Integer... progress) {
  45. setProgressPercent(progress[0]);
  46. }
  47.  
  48. protected void onPostExecute(Long result) {
  49. showDialog("Downloaded " + result + " bytes");
  50. }
  51. }.execute(url1, url2, url3);
  52. // Modified Code from google Android API
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement