So, the solution I came up with is the following:
1.) Define a listener interface for pre and post events.
2.) Implement a listener by activity
2.) Define a task wrapper class that accepts a listener and that has an internal AsyncTask that is called in 'exec'.
3.) Internal AsyncTask notifies the listener of onPreExecute and onPostExecute
4.) After notification, the activity updates its user interface.
For testing in Office:
1.) Create a serial version of the wrapper class by inheriting from it, and then override the exec method to execute in sequence:
- notify the listener about the task as starting.
- to perform the task.
- notify the listener that the task has been completed.
To test the asynchronous version of the task.
1.) Use CountdownLatch and Runnable in the unit test method. Since there will be no UI updates, you will not have any WrongThreadExceptions errors.
source share