Search code examples
androidflashcameraonconfigurationchanged

android camera flash light turns off on changing orientation


Possible Duplicate:
Flash light is getting switch off while changing the orientation

I am building an android app. On configuration change the flash light goes off. Then I need to again click the ON button to make it on. how can it remain switched on in my app?


Solution

  • Basic problem is that configuration change by default recreates Activity, so if you do some recurse management in activity you have to remember that.

    There are two opposite solutions:

    1. disable recreation of Activity on configuration change by adding in manifest property android:configChanges of Activity list of configuration changes which you will handle manually, for example "keyboardHidden|orientation|screenSize" (screenSize is needed since Adnroid 3.1). In this case you can handle configuration change by overriding method onConfigurationChanged.

    2. handle recreation of activity by overriding method onSaveInstanceState and saving state of activity there inside of bundle. Then in onCreate when parameter savedInstanceState is set (not null) you should restore state from that bundle (restore state of flash light).

    Choice of method depends of you activity design.