In my application, I'm having an AsyncTask that uploads some data to the server and interacts with the calling activity using an interface "FetchCompleteListener " that I wrote.
The calling activity implements a FetchCompleteListener and passes its own instace to the AsyncTask.
The given AsyncTask calls FetchCOmpleetListener's onFetchCoMplete in onPostExecute()
My question is - what happens in the following scenarios:
Is this a case of memory leak? Will my application crash when I try to call onFetchComplete in onPostExecute()?
You should always decouple background tasks from your ui. you can do one of the following:
Your ui will register a broadcast receiver inside onResume (of course unregister that in onPause), the background task will send a broadcast that will be caught by the ui when it is active
You can queue up your result in some service classes (or what suits you best), when the corresponding ui comes alive it will take results from queue (based on some TAG)
you can use an EventBus like Otto or greenrobot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.