Reputation:
I have a lot ot async tasks in my activity. If screen rotation occurs - they gone. What to do to prevent asynctasks from trowing exception?
Upvotes: 0
Views: 552
Reputation: 96
The most proper way to this is to use a fragment to retain the instance of the async task, over rotations.
Here is a link to very simple example making it easy to follow and integrate this technique into your apps. This works brilliantly all buttons and images etc are redrawn as expected
https://gist.github.com/daichan4649/2480065
Upvotes: 0
Reputation: 1277
use
android:configChanges="keyboardHidden|orientation"
as a attribute of your Activity
in AndroidManifest.xml
file to prevent reload Activity on screen rotation .
Upvotes: 1
Reputation: 9005
I think exception is due to the re starting of the activity in orientation changes, if use android:configChanges="orientation|keyboardHidden"
for your activity in your manifest, which prevents restart
Upvotes: 2