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!

  1. first of all, in situation better go service instead of asynctask. in case, service should stop once task finished.
  2. 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.

  3. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -