0

I have AsyncTask and i want to write data to a file.

should I write data to the file in UI thread "OnProgressUpdate" or on the background thread "doInBackground"

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 2
    Write in doInBackground(), if your file size is large. – Nigam Patro Nov 25 '15 at 10:40
  • 3
    _writing data to a file_ has nothing to do with the UI. Then it should be in a background thread. – Emil Nov 25 '15 at 10:42
  • Read the AsyncTask docs, onProgressUpdate is meant to just notify the user about the current action progress, all task should be done in doInBackground. – Nanoc Nov 25 '15 at 10:45

2 Answers2

1

onProgressUpdate() is used to operate progress of asynchronous operations via this method

This callback can be triggered from within the body of the doInBackground() method by calling publishProgress()

Reading and Writing is always better to do in background thread. Well it's always a better UX!

Community
  • 1
  • 1
johnrao07
  • 6,690
  • 4
  • 32
  • 55
1

No second thought. Do it in doInBackground().

cgr
  • 4,578
  • 2
  • 28
  • 52