活动生命周期x电源按钮X锁屏 [英] Activity Lifecycle X Power Button X Lock Screen

查看:130
本文介绍了活动生命周期x电源按钮X锁屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我preSS电源键,屏幕将自动关闭(全黑),系统破坏我的活动,然后重新创建它:

When I press the power key, the screen turns off (completely dark), the system destroys my activity and then recreates it:

03-28 22:48:00.934: V/[BB](5809): [GameControl] onPause
03-28 22:48:01.444: V/[BB](5809): [GameControl] onDestroy
03-28 22:48:01.724: V/[BB](5809): [GameControl] onCreate
03-28 22:48:03.016: V/[BB](5809): [GameControl] onResume
03-28 22:48:03.016: V/[BB](5809): [GameControl] onPause

这是造成的,因为我的活动都有一个固定的方向(横向)与锁屏的画像。

This is caused because my activity has a fixed orientation (landscape) and the lock screen is portrait.

我通过设定一个固定的纵向测试这个理论,这件事情不会发生。我也查了getResources()getConfiguration()值:​​

I tested this theory by setting a fixed portrait orientation and the issue doesn't happen. I also checked the getResources().getConfiguration() values:

{ scale=1.0 imsi=724/31 loc=pt_BR touch=3 keys=2/1/1 nav=1/1 orien=2 layout=17 uiMode=17 seq=36}
{ scale=1.0 imsi=724/31 loc=pt_BR touch=3 keys=2/1/1 nav=1/1 orien=1 layout=17 uiMode=17 seq=37}
{ scale=1.0 imsi=724/31 loc=pt_BR touch=3 keys=2/1/1 nav=1/1 orien=2 layout=17 uiMode=17 seq=38}

如何才能避免这种情况? 我不希望我的活动破坏了锁屏!

How can avoid that? I don't want my activity destroyed by the lock screen!

推荐答案

解决的办法就是添加一个机器人:configChanges =定位| keyboardHidden |屏幕尺寸你的活动在AndroidManifest.xml中

The solution is to add a android:configChanges="orientation|keyboardHidden|screenSize" on your Activity in your AndroidManifest.xml.

这篇关于活动生命周期x电源按钮X锁屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆