I just developed a screen saver app and I found a strange behavior in its lifecycle. My work flow is like this:
- start my
RegisterService
, where I callregisterReceiver
method to register aBroadcastReceiver
, which can receiveACTION_SCREEN_OFF
.
2.In the onReceive
method of this BroadcastReceiver
, I start an activity as the screensaver.
3.In the activity, I write Log.i()
statement to track its running.
My question is:
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.
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!