I start AsyncTask and put Context in constructor of the Task.
On onPostExecute I want to know is my activity active now and was not recreated. How it’s better to do?
For this I can:
-
create randomNumber in
onCreateActivity and then put it inApplicationclass; -
onPause/onDestroy set randomNumber to 0 and in
onResumerestore randomNumber; -
in
onPreExecute()get randomNumber and inonPostExecutecompare randomNumber with Application randomNumber.
May be I can use Context for making decision … ?
There are many approaches to check if the activity is still there.
I usually create a
SkeletonActivitywith the following structure:Now let all your activities extend this
SkeletonActivity. Finally change this Base Class to change the paused flag as you wish (For example update it inonDestroy()Another way would be to have a Context instance inside your
SkeletonActivity: