I am new to android development. I would like to accomplish a task described as follows:
- A main activty which calls external class(the other class would extend
AsyncTask) to parsexmland receivejsonby requesting to web service and starts aProgressDialog. - The class performs
xmlandjsonparsing in itsdoInBackgroundmethod. - In the
onPostExecutemethod after parsing is complete, dismiss theProgressDialogthat was set in the main activity. - I could do this by passing the ProgressDialog object to the parsing class and dismissing the same object in its
onPostExecutemethod.
I think passing an instance of UI object as argument is not a good approach to program, I hope there must be some other ways to work around.
Please suggest.
Thank you
The easiest way to decouple these is to use an interface:
WorkDoneListener) with a single method:workDone().WorkDoneListenerand implementworkDone()to dismiss the dialog.WorkDoneListener. Stash the reference in a member field.onPostExecute, call the listener’sworkDone()method.