Android app restarted after launching lock screen

I played all day with the states, trying to understand why, when I press the power button to open the lock screen, my application loses focus and calls it onStop () (as it should), but then it calls onStart () again, until the hte screen does not go out. This causes me a problem because some sounds in my application (and presumably other things) start playing again when the lock screen is active.

How can I make sure it is properly shaded and stopped when the lock screen is active?

+5
source share
1 answer

I recently ran into this exact issue. In AndroidManifest.xml, make sure you have this:

android: configChanges = "keyboardHidden | orientation"

This will prevent your activity from restarting during configuration changes. Look at the configuration change yourself . Thus, your application will listen to events that will lead to a restart - for example, orientation and changes in keyboard visibility - and process them in your activity.

There is also a very similar question here: Restarting activity during Android rotation

+7
source