简体   繁体   English

Android在进入睡眠状态时会更改活动

[英]Android changes activity when it goes to sleep

I'm maintaining an Android app that controls an industrial process. 我正在维护一个控制工业流程的Android应用程序。 It has a main Activity/screen which allows you to selects various industrial tasks, and each task has its own activity/screen. 它有一个主要的活动/屏幕,允许您选择各种工业任务,每个任务都有自己的活动/屏幕。

The problem - if the user is in one of these other Activities and the droid goes to sleep (say because the worker takes a break or goes to lunch), when it wakes up again it's back in the main Activity! 问题 - 如果用户处于其中一个活动中并且机器人进入睡眠状态(比如因为工作人员休息或去吃午餐),当它再次唤醒时它会回到主要活动中!

This is hard to debug because to debug it I have to be connected to the USB and when it's attached to USB it doesn't go to sleep. 这很难调试,因为调试它我必须连接到USB,当它连接到USB时,它不会进入睡眠状态。

1. What Activity Lifecycle events are associated with it going to sleep? 1.哪些活动生命周期事件与其进入睡眠状态相关联? What does it actually mean to go to sleep - the display goes off but obviously other stuff is happening, too, because when it wakes up it's in a different activity. 它真正意味着什么才能入睡 - 显示器熄灭但显然其他东西也在发生,因为当它醒来时,它处于不同的活动中。

2. Is there a way I can allow it to enter sleep mode even when attached to USB so I can set breakpoints and debug this properly? 2.有没有办法可以让它进入睡眠模式,即使连接到USB也可以设置断点并正确调试?

Details: 细节:

  • Samsung Galaxy Player (basically Samsung phone without the phone) running 2.35. 三星Galaxy播放器(基本上没有手机的三星手机)运行2.35。
  • Activity that's open when it goes to sleep uses the default Standard launch mode. 进入睡眠状态时打开的活动使用默认的标准启动模式。

When android goes to sleep, the top most activity receives onPause , but it still remains as the top most activity in the activity stack, and therefore it will receive onResume and will be started when the device awakes. 当android进入休眠状态时,最顶层的活动会收到onPause ,但它仍然是活动堆栈中最顶层的活动,因此它将接收onResume并在设备唤醒时启动。

The reason you see your main activity when the device wakes up is that there should be some code in your onPause which forces the top most activity to finish after onPause (similarly there might be some settings. For example, setting noHistory to true in AndroidManifest.xml for an activity forces the activity to shutdown itself when it receives onPause, and so when you go back, you will see Main Activity on top). 设备唤醒时您看到主要活动的原因是onPause中应该有一些代码强制在onPause之后完成最高活动(类似地可能有一些设置。例如,在AndroidManifest中将noHistory设置为true。活动的xml会强制活动在收到onPause时自行关闭,因此当您返回时,您将看到主要活动位于顶部。

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

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