On Fri, Sep 10, 2010 at 12:46 PM, Romain Guy <romain...@android.com> wrote: > Option #1 is a lot more intrusive. You lose the ability to > automatically switch layouts, drawables, etc.
Worst-case scenario: Step #1: Take your UI setup that is in onCreate() and move it to a separate method (e.g., setupViews()) Step #2: Call setupViews() from onCreate() Step #3: Call setupViews() from onConfigurationChanged() Done. ~4 lines of code. And it's the exact same code path that a destroy/recreate will go down, so it's not like this adds unusual performance overhead. There are certain circumstances where this may not work (e.g., GLSurfaceView and a game), but you needed to do extra work for those cases, anyway, to handle the destroy/recreate cycle. > Saving and restoring an AsyncTask is not difficult. No, it's not. The question is: is it reliable? None of the AsyncTask documentation (class, article, etc.) covers this case. It *appears* that you can write an AsyncTask such that onPostExecute() or onProgressUpdate() will not be called in the middle of the activity transition. However, that's not documented and hence not guaranteed, and so while I'll describe a pattern that seems to work, I personally don't trust it any further than I can throw your large Froyo lawn ornament. If somebody could give us the recipe that is guaranteed to work (i.e., works today, and is going to work in Android 2.3/3.0/Turbo System 5000), that'd be *wonderful*. Actually, I lied earlier. I'd choose Option #4: Option #4: Don't do the AsyncTask in an activity. Use a Service and have it do the AsyncTask, or use an IntentService if the sole purpose of the service is to do stuff in a background thread. In particular, an IntentService would be good for a download that you want to happen regardless of what may go on with an activity (e.g., Android Market downloading an APK), and so you don't need to worry about canceling it. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in London: http://skillsmatter.com/go/os-mobile-server -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en