creating interactive screen saver with daydream logicchip thumb

Creating Interactive Screen Saver with Daydream

DayDreams are interactive screensavers launched when a charging device is idle, or docked in a desk dock. Dreams provide another modality for apps to express themselves, tailored for an exhibition/lean-back experience. So it’s found here and an official example can be found here. DayDream feature was introduced in  Android 4.2,brings this kind of laid-back, whimsical experience to Android phones and tablets that would otherwise be sleeping.However if you haven’t checked it out, you can turn it on in the Settings app, in Display > Daydream touch When to Daydream to enable the feature when charging or docking or both in some cases.

An attract mode for apps

Apps that support Daydream can also take advantage of the full Android UI toolkit in this mode, which means it’s easy to take existing components of your app — including layouts, animations, 3D, and custom views—and remix them for a more ambient presentation.

And since you can use touchscreen input in this mode as well, you can provide a richly interactive experience if you choose.

.Daydream also provides an opportunity for your app to show off a little bit. However you can choose to hide some of your app’s complexity in favor of one or more visually compelling experiences that can entertain from across a room, possibly drawing the user into your full app, like a video game’s attract mode.

The architecture of a Daydream

In fact each Daydream implementation is a subclass of android.service.dreams.DreamService. When you extend DreamService, you’ll have access to a simple Activity-like life-cycle API.

As a matter of fact to be available to the system, your DreamService should be declared in the manifest as follows:

                <action android:name="android.service.dreams.DreamService" />
                <category android:name="android.intent.category.DEFAULT" />

                android:resource="@xml/dream_info" />

Daydream is only available on devices running version 4.2 of Android , which is API Level 17 and above.When targeting api level 21 and above, you must declare the service in your manifest file with the BIND_DREAM_SERVICE permission.

In fact additional information is specified with the <meta-data> element. So additional information for the dream is defined using the <dream> element in a separate XML file. As a result it allows you to point to an XML resource that specifies a settings Activity specific to your Daydream. Currently, the only addtional information you can provide is for a settings activity that allows the user to configure the dream behavior  For example:


<dream xmlns:android=""
    android:settingsActivity="com.logicchip.blog_15_daydream.MainActivity" />

This makes a Settings button available alongside your dream’s listing in the system settings, which when pressed opens the specified activity.

In order to specify your dream layout, call setContentView(View), typically during the onAttachedToWindow() callback For example:

public class DayDream extends DreamService {

    Handler handler;
    Runnable runnable;
    SimpleDateFormat simpleDateFormat;
    Calendar calander;

    public void onAttachedToWindow() {
        // Hide system UI
        // Set the dream layout

    public void onDreamingStarted() {

    public void TimeChange12(){
        handler = new Handler();
        runnable = new Runnable() {
            public void run() {
                handler.postDelayed(this, 1000);
                try {
                    calander = Calendar.getInstance();
                    simpleDateFormat = new SimpleDateFormat("hh : mm : ss");
                    TextView txtTime= (TextView)findViewById(;

                } catch (Exception e) {
        handler.postDelayed(runnable, 0);

Consequently layout for dreaming can be whatever we like,  can include animation interactive ui etc.However, be aware that if your screen saver is using too much of the available processing resources, the Android system will stop it from running to allow the device to charge properly.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

        android:text="23 : 59 : 59"



Even so “Creating Interactive Screen Saver with Daydream” is explained above you can still download it from here, You can modify the code us u like. In like manner feel free to comment your doubt’s below. Does our tutorials help you then help as spread the word, like and share.


2 thoughts on “Creating Interactive Screen Saver with Daydream”

  1. Hi –

    It looks like you have something here that could help me, but it seems to have been written for those with lots of experience.

    I’m pretty new to Android programming. When I create the project, which options do I choose? No Activity? Empty Activity? Something else?

    When I try to get the permission BIND_DREAM_SERVICE I get a message indicating that that’s a “system” permission. How do I get around that?

    When I try to register the service in the manifest, the line
    causes a “not resolved” message for .DayDream.

    how do I get around these problems?


Leave a Reply Cancel reply

Exit mobile version