How do I avoid reloading the activity with asynctask class in activity when the user changes orientation, in android? Can anybody give an example?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
How to preserve 2 'Alert' Dialogs openened one from another when orientation changes? Believe me, it is not simple to restart 3 fragment activity with 2 Dialogs opened. Programers do not have time to do unnecessary programming. It is easier to either stop the orientation change for some part of the app, or block it for always.
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.
Chirag have already correctly pointed out the solution.
I just want to add that, restart of Activity has nothing to do with the
AsyncTask
in it. By default, when there are any config changes,the activity is restarted UNLESS the config change is explicitly handled by the Activity. This is done by making an entry in manifest file.Go through this link developer guide : android:configChanges
NOTE: Check the code on a device not on emulator. Because I had faced similar problem earlier. The same code didn't worked on emulator but it worked on device perfectly. So add the entry for
android:configChanges
in manifest and check the application on a android device instead of emulator.And I second @hackbod. Do it only if necessary!