I have a class which downloads information from a website.
I’m using the AsyncTask at the moment to get it, so the ui will stay responsive.
I understand how to update the GUI using the publishProgress and onProgessUpdate, but what if I have a big method (or function) within a different class?
It is easier to show with the code:
@Override
protected ArrayList<Card> doInBackground(Void... voids)
{
Looper.prepare();
publishProgress("Creating object");
SomeClass someClass = new SomeClass();
publishProgress("Performing a long operation");
ArrayList<Card> = someClass.getCards();//This method takes a long while. I would like to call the "publishProgress" method from the "someClass".
return athopGetter.getCards();
}
You can pass the task reference to ‘someClass’, since publishProgress is protected final, you need to implement your own publish method, which simply invoke publishProgress,
or you can use reflection to invoke publishProgress directly.