Suppose I have a innerclass extends asynctask called A and the outerclass extends Activity B.
Is it thread-safe that the code in A access or modify the instance variable in Activity B?
Suppose I have a innerclass extends asynctask called A and the outerclass extends Activity
Share
No, an AsyncTask runs in a separate thread so you’ll have to do the usual thread synchronization if the Activity and AsyncTask share state (in this case instance variables) while the AsyncTask is running.
Generally, to make it easy, you implement
onPublishProgress()andonPostExecute()to publish state from the AsyncTask to the Activity, since both methods are posted to run in the UI thread.