I've actually been looking for a solution to this quandary for some time. 
The quickest is just to add this property to each activity tag in your 
AndroidManifest.xml file:

*android*:configChanges="keyboardHidden|*orientation*"


However, this won't keep your task/download working if, say, the user takes 
a call or presses the home key. However, although the official documentation 
advises against using this method, it is actually used in the messaging 
application.

Anyways, you probably want a more robust method. To do this, you can either:

   1. Create a service and work with downloads in there, and communicate 
   with your UI activity if it exists. This approach is better if you have some 
   sort of download manager or feed updater that must work in the background
   2. Work in AsyncTask, which is better for shorter tasks (if you want to 
   quickly fetch a file, parse it, and update the user interface). There are a 
   few techniques here. You can pass references to your task when the activity 
   is destroyed between orientation changes 
   with onRetainNonConfigurationInstance(). Or, you can hold the reference to 
   your task by holding it in the Application object, accessible to all 
   activities. Have a look at 
   
http://www.fattybeagle.com/2011/02/15/android-asynctasks-during-a-screen-rotation-part-ii/
 for 
   code (and read Part I where the author goes over the other possibilities)
   
Hope this helps!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to