在我的屏幕保护程序应用程序生命周期的奇怪行为 [英] Strange lifecycle behavior in my Screen Saver App

查看:160
本文介绍了在我的屏幕保护程序应用程序生命周期的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开发保护程序的应用程序的屏幕,我发现了一个奇怪的行为在其生命周期。 我的工作流程是这样的:

I just developed a screen saver app and I found a strange behavior in its lifecycle. My work flow is like this:

  1. 在开始我的 RegisterService ,在那里我叫 registerReceiver 方法来注册一个的BroadcastReceiver ,可接收 ACTION_SCREEN_OFF
  1. start my RegisterService, where I call registerReceiver method to register a BroadcastReceiver, which can receive ACTION_SCREEN_OFF.

2.In的的onReceive 这种方法的BroadcastReceiver ,我开始一个活动的屏幕保护程序。

2.In the onReceive method of this BroadcastReceiver, I start an activity as the screensaver.

3.In活动,我写 Log.i()语句来跟踪其运行。

3.In the activity, I write Log.i() statement to track its running.

我的问题是:

当屏幕超时,或者当我preSS POWER键,屏幕会关闭,系统将发送ACTION_SCREEN_OFF消息。如我所料,我的接收器启动屏幕保护程序的活动。不过,我觉得这个活动电话的onCreate() onResume()的onPause() onResume()根据logcat的输出顺序。

When the screen times out, or when I press the POWER key, the screen turns off, and the system will send ACTION_SCREEN_OFF message. As I expect, my receiver starts the screen saver activity. However, I find this Activity calls onCreate(), onResume(), onPause(), onResume() sequentially according to the output in logcat.

看起来好像有些一个活动来到我的屏幕前,并立即完成,所以我的屏幕保护程序调用的onPause()然后 onResume()

It seems as if some a activity comes at front of my screensaver and finishes immediately, so my screensaver calls onPause() and then onResume().

你知道吗?这个问题的障碍我编程,请大家帮忙。谢谢!

Any idea? This problem handicaps me in programming, please help. Thanks!

推荐答案

我可以推荐你的东西很容易,可能为你工作,如果你不想要的暂停行为你为什么不尝试覆盖的方法的onPause(),只是无可奈何:P 不叫 super.onPause() 并这将结束它的行为。

I can recommend you something very easy that might work for you, if you do not want the pause behavior why don't you try to Override the method onPause() and just do nothing :P don't call super.onPause() and that will terminate the behavior of it.

这可能为你工作,声明一个静态变量,增加1对onResume()方法,并返回到0时的onStop()被称为其它的东西。现在只是评价的时候,onResume()之称,如果该变量为0则是第一次,别的什么也不做。

Other thing that might work for you, declare a static variable, add 1 on the "onResume()" method and return to "0" when "onStop()" is called. now just evaluate when the "onResume()" is called and if the variable is "0" then is the first time, anything else do nothing.

我希望这有助于原因没有在你的问题上没有太多的信息更具体。

I hope this helps cause there is no much information on your question to be more specific.

这篇关于在我的屏幕保护程序应用程序生命周期的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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