-2

It know this is possible in multiple ways like with bundles, params... But what is the shortest easiest way to update a textview or string data from an AsyncTask's OnPostExecute method?

Tachanka
  • 133
  • 1
  • 1
  • 9
  • Need to describe more. Do you want to update textview text from service call? – Shohan Ahmed Sijan Jan 14 '17 at 10:12
  • No I want to update it when the AsyncTask finishes. I found some examples, but those have AsyncTask inside the Activity.class file, I have it as a seprate class as I need to to get general data with which I can update textViews in multiple fragments. – Tachanka Jan 14 '17 at 10:16
  • updating textView require UI thread regardless if you need to use AsyncTask or not. – Maytham Fahmi Jan 14 '17 at 10:18
  • @Tachanka then pass the View in your `AsyncTask` subclass constructor as `WeakReference`. – Enzokie Jan 14 '17 at 10:19
  • You can solve it in many ways. You can create interface. For example A simple solution may be create a static function/functions for where you need update and call that function when OnPostExecute done. – Shohan Ahmed Sijan Jan 14 '17 at 10:22

1 Answers1

0

I think the most easiest way to update your view components is, you need to set your view components and class members in either your class or in AsyncTask. After finishing grabbing data from server or processing, in AsyncTask OnPostExecute function, you can directly manipulate your members, e.g,

TextView.setText(your string here).

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
Chauyan
  • 157
  • 8