简体   繁体   English

带/不带锁屏功能的Android活动生命周期

[英]Android Activity Lifecycle With/Without Lock-screen

I'm trying to find out what the difference is in the activity lifecycle when a lock-screen is enabled versus disabled. 我试图找出启用和禁用锁定屏幕时活动生命周期的区别。

Scenario A (no lock-screen) 方案A(无锁屏)

  • App is running 应用正在运行
  • power button is hit to turn display off 按下电源按钮以关闭显示屏
  • power button is hit to turn display on 按下电源按钮以打开显示
  • App is immediately resumed 应用立即恢复

Scenario B (lock screen enabled, swipe to unlock) 方案B(启用锁定屏幕,滑动即可解锁)

  • App is running 应用正在运行
  • power button is hit to turn display off 按下电源按钮以关闭显示屏
  • power button is hit to turn display on 按下电源按钮以打开显示
  • Swipe screen to unlock 轻扫屏幕来解锁
  • App is resumed (but we are getting a bug in the display, which is where we are trying to find the difference) 恢复了应用程序(但我们在显示屏中发现了一个错误,这是我们试图找到差异的地方)

I have printed out the activity lifecycle for both scenarios and they show up identical for both scenarios. 我已经打印出了这两种情况下的活动生命周期,并且它们在两种情况下都表现出相同的状态。

What might be the difference in the lifecycle that would cause this different behavior when using lock-screen versus no lock-screen? 使用锁屏与不使用锁屏时,会导致不同行为的生命周期会有什么不同?

Take a look at this documentation . 看一下这个文档 It could be that the lock screen would imply that the app process is killed and therefore data is lost (which is necessary to present the page and therefore the app crashes). 锁定屏幕可能意味着应用程序进程被杀死,因此数据丢失了(这是呈现页面所必需的,因此应用程序崩溃了)。 I would suggest to debug the activity states to find the answer you're looking for. 我建议调试活动状态以找到所需的答案。

You can test it with writing Logs into onResume(), onCreate(), onPause(), onDestroy() etc. 您可以通过将Logs写入onResume(),onCreate(),onPause(),onDestroy()等进行测试。

Also pressing Power button and and opening LockScreen changes the devices screen orientation into "Portrait" mode(Phones and tablets with locked rotation only). 同时按下电源按钮并打开LockScreen可以将设备的屏幕方向更改为“纵向”模式(仅旋转锁定的手机和平板电脑)。 It may cause different reactions you are mentioned about. 它可能会引起您提到的不同反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM