Over a million developers have joined DZone.

Android 4.2: How to Create DayDream?

DZone's Guide to

Android 4.2: How to Create DayDream?

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.


This article is extension of my previous article about DayDream: What exactly DayDream feature is about?. Now i assume you understood about DayDream, so now i am proceeding further for developing a small example of DayDream.

Step 1: Create a sample project to build this demo example

I have created a simple project to give this demo, you can follow below steps to create DayDream for your Android application.

Step 2: Create a class and extends DreamService

FYI, DreamService is added in API Level 17 and you can it extend to create custom DayDream. LifeCycle of the DreamService is as follows:

onAttachedToWindow() Use this for initial setup, such as calling setContentView().
onDreamingStarted() Your dream has started, so you should begin animations or other behaviors here.
onDreamingStopped() Use this to stop the things you started in onDreamingStarted().
onDetachedFromWindow() Use this to dismantle resources your dream set up. For example, detach from handlers and listeners.
Lifecyle of DreamService

Here in this example i have just included TextView to display Hello World message, instead you can create your own XML layout and set it through setContentView() method inside onAttachedWindow() method.

package com.technotalkative.daydreamexample;
import android.graphics.Color;
import android.service.dreams.DreamService;
import android.widget.TextView;
public class MyDreamService extends DreamService {
   public void onAttachedToWindow() {
       // Allow user touch
       // Hide system UI
       // Set the dream layout
       TextView txtView = new TextView(this);
       txtView.setText("Hello DayDream world from TechnoTalkative.com !!");
       txtView.setTextColor(Color.rgb(184, 245, 0));

Step 3: Declare this MyDreamService service in AndroidManifest file

This step is necessary to make our DayDream available to the system.

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

Step 4: Run this application

TechnoTalkative DayDream Example

Now, lets run this application, if it executes well then your DayDream will become available inside the Settings->Display->DayDream. Yes as we did nothing for Activity screen we will see nothing in app screen.

You can see TechnoTalkative – DayDream is available inside DayDream settings. Now select it and press START NOW it would be saying Hello DayDream world from TechnoTalkative.com :)


TechnoTalkative - DayDream example output

Download source code of this example: DayDream Example – 1

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}