How do I switch orientations in android faster?
I have an android app that has to lo开发者_Python百科ad very large files on start up. any time it switches orientations, it has to destroy and recreate the activity, causing the large files to reload. this takes about 30 seconds, this is pretty inconvenient if I were to actually publish this. I am sure that I am doing something wrong here. I have heard of onSaveInstanceState() and onRestoreInstanceState(), but I have no idea how to use them. does any body know how I could use this to speed up the Orientation change?
Use onRetainNonConfigurationInstance()
to pass your data from the old activity to the new activity.
Or, store the data in a static data member (but be careful about garbage collection).
Or, store the data in a custom Application object (as Reto Meier suggests here).
While @foxx1337 suggests android:configChanges="orientation"
, not only is that answer incomplete, but it is not recommended practice.
Start with android:configChanges="orientation"
in your AndroidManifest.xml. Also have a look at Activity restart on rotation Android.
精彩评论