Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, app restarted after lock screen starts

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?

like image 499
Hamid Avatar asked Dec 15 '10 15:12

Hamid


People also ask

Why do my Android apps keep restarting?

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.

How do I stop Android apps from restarting?

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.

Why do my apps restart everytime I open them?

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.

Why do my Android apps restart all over again if I minimize them?

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.


1 Answers

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

like image 130
Julio Gorgé Avatar answered Sep 20 '22 20:09

Julio Gorgé