0

I have an android app that has to load 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?

Ephraim
  • 8,352
  • 9
  • 31
  • 48

2 Answers2

4

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.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • how would I use it too pass information? lets say that I want to pass a String that contains the text: "this is what I am passing". how would I save and retrieve that information in the code? – Ephraim Feb 02 '11 at 23:24
  • The easiest way is to store your string as a static variable: public static String myString = "this is what I am passing"; This suffers from the problems outlined above. Have you had a peruse through these: http://developer.android.com/guide/topics/fundamentals.html ? – Tom R Feb 02 '11 at 23:30
0

Start with android:configChanges="orientation" in your AndroidManifest.xml. Also have a look at Activity restart on rotation Android.

Community
  • 1
  • 1
foxx1337
  • 1,859
  • 3
  • 19
  • 23