Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

AsynTaskCompat Use in fragment

By: Pauland on Dec 5th, 2012  |  syntax: Java  |  size: 0.64 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private CustomTask mTask;
  2.  
  3. @Override
  4. public void onActivityCreated(Bundle savedInstanceState)
  5. {
  6.         super.onActivityCreated(savedInstanceState);
  7.         if(this.mTask == null)
  8.         {
  9.                 this.mTask = new CustomTask ()
  10.                 {
  11.                         @Override
  12.                         protected void onPostExecute(Response result)
  13.                         {
  14.                                 //Your stuff
  15.                                 Fragment.this.mTask = null;
  16.                         }
  17.        
  18.                         @Override
  19.                         protected void onCancelled()
  20.                         {
  21.                                 Fragment.this.mTask = null;
  22.                         }
  23.                 };
  24.                 this.mTask.ExecuteCompat();
  25.         }
  26. }
  27.  
  28. @Override
  29. public void onDestroyView()
  30. {
  31.         if (this.mTask != null && this.mTask.getStatus() != AsyncTask.Status.FINISHED)
  32.                 this.mTask.cancel(true);
  33.         super.onDestroy();
  34. }