Consider an AsyncTask started in an Activity. What happens if the Activity is paused or destroyed? Will onPostExecute() run? If yes, what UI thread will be used?
Just wondering.
Many thanks in advance.
UI thread is available throughout the visible life of your application which may span on a combination of multiple activities.
Anything you change in views must be performed on UI thread and onPostExecute of AsyncTask reflects the same logic by executing the instructions inside on UI thread.
You may use runOnUiThread in your own Thread
to make changes on Views. But since AsyncTask has onPostExecute method (which also runs on UI thread) so you dont logically need to use runOnUiThread there.
Update
Regarding your question: Yes, onPostExecute will still be called (because its invoked by a separate thread) even if your activity is destroyed and if the method will manipulate Views, you'll simply get Force Close error because reference to your activity is not available anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With