I’m writting an android app that instantiates a worker thread to update UI every second.
When I press “home” button, the thread still running, and when I restart the app from home, everything works fine: the UI is still updating every second.
But, when I press “back” button, and then restart the app from home, the app didn’t get the UI updates sent from worker thread.
What can I do to get this thread reference again?
I need to do an app that works like a chronometer. If the user leaves the app without stop it, the work must continue. Is thread a good choice? Can I solve this using AsyncTask or Service?
Note: pressing “back” button, the onDestroy() method is executed. When I press “home” button, onDestroy() isn’t executed.
(sorry for my bad english)
You should need a Boolean variable for handling UI update from background thread. by this variable you can control Thread when app is going distory and paused by pressing back and Home Key. change your code as: