Funky android activity behavior when screen turns off?

后端 未结 2 1380
误落风尘
误落风尘 2021-02-15 12:41

I\'m seeing some interesting activity flow when android turns off the screen and locks the screen... my app goes through the regular flow, onCreate, onStart and onResume. Then,

相关标签:
2条回答
  • 2021-02-15 13:29

    In the activity's manifest, for each application add:

    android:configChanges="orientation|keyboardHidden"
    

    This tells android you'll handle these two cases yourself - although of course you're lying: you won't do shit to handle them, but Android doesn't know that. This works great for apps/games/etc running for example in landscape mode and never change orientation.

    0 讨论(0)
  • 2021-02-15 13:45

    It may not be what you are seeing, but on my phone, something like this happens because sleep mode is always in one orientation, and if the app was in the other one it gets killed and recreated in the sleep orientation... rather suboptimal if you ask me.

    It sounds to me like you may not have things such as your startup sound tied to sufficiently specific causes. What happens if you rotate the phone while it's "on" ? At any rate, you should be able to detect that the screen is not on and not do (or defer) a real startup.

    If an implicit orientation change is the culprit, you can change how your application is treated with these - set things to claim your application can change on the fly instead of having to be recreated.

    0 讨论(0)
提交回复
热议问题