Avoid reloading activity with asynctask on orientation change in android

mohan picture mohan · Mar 17, 2011 · Viewed 33.9k times · Source

How do I avoid reloading the activity with asynctask class in activity when the user changes orientation, in android? Can anybody give an example?

Answer

hackbod picture hackbod · Mar 17, 2011

Please turn off config changes as a last resort. Your app must work correctly when this happens. If you turn off the orientation config change because it breaks, your app will still break in other and some times more subtle way. Allowing the activity to be restarted due to an orientation config change is a very good way to easily test these important code paths of your app that are otherwise much less often exercised but still will result in failures in your users' hands.

To transfer active objects across Activity instances, use the new fragment static library which allows you to make a fragment that is retained for you across instances.