Question

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?

Was it helpful?

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.

OTHER TIPS

Add android:configChanges="keyboardHidden|orientation" to your activity in android manifest file.

When ever you are changing the orientation the full activity is been destroyed and a new activity is been created.So what happening is that the activity is loosing the current state of the flash and it turns off.

Try disabling the orientation changes in the manifest.And save the current state of the flsh in the Onstop and reset the state in the OnStart.

This will work for you I believe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top