android: Difference between pressing home button and power button?

倖福魔咒の 提交于 2019-12-06 12:27:24

I have discovered the same issue and i believe that when the PowerButton is pressed, the device changes from landscape to portrait to display the lock-screen. In my case i see the surfaceChanged instead of the expected destroyed, but the width and height show that the change went from landscape to portrait.

Edit

On my Galaxy S2 with 4.1.2 when i press the PowerButton the device only goes to "onPause" and the surface only changes (from landscape to portrait). When i hit the HomeButton, then it goes to "onStop" and the surface is destroyed without a change.

If you try the following in "onPause" you can determine whether the screen is still on or off

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();

API lvl 7.

AFAIK it is safe to call "onStop" yourself in "onPause" as you cant cause the true lifecycle to change, you just execute the code that you wrote into the stop (the super method seems to do nothing, i checked the Activity source)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!