0

I want to prevent my activity from restarting when I change the orientation from portrait to landscape, so I call this on the corresponding activity on manifest:

android:configChanges="orientation|screenSize"

My activity isn't restarted anymore but unfortunately the drawables and layout I have for the activity on landscape orientation isn't loaded.

When I removed the line above, the drawables and layout are loaded correctly but then the activity restarted.

is there any way to prevent the activity from restarting while the landscape resources are still loaded correctly?

hectichavana
  • 1,436
  • 13
  • 41
  • 71

1 Answers1

2

The best solution is save the state before rotation happens, let the system reload normally your activity and then repopulate it with the previously saved state. You can do that overriding onSaveInstanceState(Bundle savedInstanceState) method.

But if you want to manage the orientation change by yourself, you can read this similar question: How to refresh an Android RelativeLayout when orientation changes without restarting the Activity?

Community
  • 1
  • 1
Stefano Ortisi
  • 5,288
  • 3
  • 33
  • 41
  • 1
    +1. Rebinding of resources is exactly why the system was designed to restart activities after configuration changes. – Ted Hopp Jul 02 '12 at 15:48
  • and what do I need to call inside the onSaveInstanceState method? Since I'm not saving any Strings,etc. I only want to save the state of the app – hectichavana Jul 02 '12 at 16:00
  • If you don't have any information to save, then there isn't any problem. If you want indeed, maybe, save some state of your buttons, or something like that, you can save some flag or whatever inside the onSaveInstanceState method. – Stefano Ortisi Jul 02 '12 at 16:04