Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What will happen while Asynctask task is running ,when the Screen orientation is change?
Posted

Rotation of the screen will cause the current Activity to be destroyed and new one recreated. If an AsyncTask is running when this happens, it could give rise to two consequences:
1. The new Activity instance might waste valuable resources by firing up the background work again, unaware that the old AsyncTask is still running.
2. When the old AsyncTask eventually finishes, it will attempt to report its results back to the old Activity instance which has already destroyed.
 
Share this answer
 
v2
AsyncTask will continue to run in the background and crash your app when it tries to post the result on the UI thread. You can use headless fragments to host an AsyncTask and ensuring that posts on the UI thread are done only when the Activity is resumed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900