I have been playing with the states all day trying to figure out why, when I press the power button to bring up the lock screen, my app loses focus and calls it's onStop() (as it should) but then it calls the onStart() again before hte screen goes off. This is causing me a problem because some sounds in my app (and presumably other stuff) start playing again while the lockscreen is active.
how can I make sure it is properly backgrounded and stopped when the lockscreen is active?
In most cases, random restarts are caused by a poor quality app. Try uninstalling apps you don't use. Be sure the apps you do use are reliable, especially the apps that handle email or text messaging. My wife recently discovered her Galaxy S5 would restart sometimes when receiving a text message.
Select Developer options>Running services and you'll be presented with a breakdown of the apps that are currently active, how long they've been running, and the impact they have on your system. Choose one and you'll be given the option to Stop or Report the app. Tap Stop and this should close the software down.
This is due to the restrictions iOS places on app developers. Apps are only allowed to stay open in the background for a few minutes (this saves RAM), so if the developer doesn't have the app save where you were last, the app will reset to its start page.
What deep clean does is, whenever you minimize an app , it releases all the memory associated with that app , and hence when you again open that app, it will start as if it is new. To check the 'deep clean' option, go to the developer options of your phone. If it is not enabled please enable it.
I faced this exact problem not long ago. In AndroidManifest.xml, make sure you have this:
android:configChanges="keyboardHidden|orientation"
This will prevent your activity from being restarted on runtime 'configuration changes'. See handling the configuration change yourself. That way your app will listen for events that would cause a restart - like orientation and keyboard visibility changes -- and handle them within your Activity.
There is also a very similar question on SO here: Activity restart on rotation Android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With