android - Using context reference after activity be finished -
i have complete button in page, when user click button, start async task , pass activity context it, finish activity dismiss activity view.
what happen if activity finished background task still need use context reference passed in? have concerns? or have alternative/better way kind of situation.
any suggestions appreciated!
- first of all, in situation better go service instead of asynctask. in case, service should stop once task finished.
even if go asynctask, try use application context can activity context below:
activity_context.getapplicationcontext();
the application context there if activity finished , avoid memory leak.
- and if want make asynctask run safely if activity finished, try not update ui in postexecute(..) method run on ui of activity finished leading exception. try background task inside doinbackground(...) runs on different thread.
hope answers question.
Comments
Post a Comment