当它进入睡眠状态的Andr​​oid变化活动 [英] Android changes activity when it goes to sleep

查看:141
本文介绍了当它进入睡眠状态的Andr​​oid变化活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维持,控制工业生产过程的Andr​​oid应用程序。它有一个主要活动/屏幕,让您选择各种工业任务,每个任务都有自己的活动/屏幕。

I'm maintaining an Android app that controls an industrial process. 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!

这是很难调试,因为调试它,我必须连接到USB,当它连接到USB它不会进入睡眠状态。

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.

1 用它睡觉相关的哪些活动生命周期事件?这是什么实际上意味着去睡觉 - 显示屏将关闭,但显然其他的东西正在发生的事情,也因为当它醒来它在不同的活动

1. What Activity Lifecycle events are associated with it going to sleep? 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 有没有一种方法,我可以允许连接到USB时,它甚至进入休眠模式,所以我可以设置断点并调试这正常吗?

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?

详细内容:


  • 三星Galaxy播放器(基本上是三星手机没有手机)上运行2.35。

  • 活动时,它进入睡眠状态这是开放使用默认的标准发射方式。

推荐答案

当机器人进入睡眠状态,最上面的活动收到的onPause ,但它仍然作为最高当设备醒来在活动堆栈最的活动,因此将获得 onResume 键,将启动。

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.

您看到您的主要活动,当设备被唤醒的原因是,应该有你的onPause一些code,迫使最上面的活动结束后的onPause(同样可能有某些设置,比如设置noHistory为true在AndroidManifest.xml为活动迫使活性关机本身,当它接收到的onPause,所以当你回去,你会看到在上面主要活动)。

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).

这篇关于当它进入睡眠状态的Andr​​oid变化活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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