Tuesday, July 19, 2011

[android-developers] Can someone tell me tips about developing a screensaver for Android

Hi! guys!
I am engaged in developing a screensaver for Android and I came cross
some difficulties:
The method I am now using is like this:

1. Start a service, where I register a BroadcastReceiver to listen to
SCREEN_OFF event.
2.In the method onReceive() of the BroadcastReceiver, I start the
screensaver activity.

As I expect, the code runs. However, from logcat, I notice the app's
flow is weird.
When the screen truns off, the BroadcastReceiver starts the
screensaver activity; then ,the activity calls onCreate()--
>onResume()-->onPause()-->onResume() sequentially. In some cases, it
calls onCreate()-->onResume()-->onPause(), and the screen keeps black.
In onResume(), I get the power lock and disable the keyguard, while I
release them in onPause().

pm=(PowerManager) getSystemService(Context.POWER_SERVICE);
km=(KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
wl=pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP|
PowerManager.SCREEN_DIM_WAKE_LOCK, DEGUG_TAG);
kl=km.newKeyguardLock(DEGUG_TAG);
In onResume(), I write:
kl.disableKeyguard();
wl.acquire();
In onPause(), I write:
wl.release();
kl.reenableKeyguard();

This weird behavior really impacts me in programming logic. Could
someone give some tips about how to create a screensaver? Should I use
some hidden APIs?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate