DayDream – Part2

This tutorial is all about creating your own Dream by Implementing DremService class. You can create custom DayDream by implementing this class in your application. DreamService is added in API Level 17 and you can extend it 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 write messages 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.

Follow the steps below and you will get your own DayDream for your android application in minutes. 😉

Step 1:

Create a sample project to build this demo example

Step 2:

Create a classCustomDreamService and extends DreamService:


package com.example.daydreampart2;

import android.service.dreams.DreamService;
import android.widget.TextView;

public class CustomDreamService extends DreamService {
public void onAttachedToWindow() {

TextView tv = new TextView(this);
tv.setText("This is your own Dream Hurray !!");
tv.setTextColor(Color.rgb(184, 245, 0));




Step 3:

Write the following into


package com.example.daydreampart2;

import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;




Step 4:

Declare CustomDreamService service in AndroidManifest file


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



Step 5:

Run this application

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


You can see CustomDayDream is available in DayDream settings. Now select it and press START NOW it would be saying. This is your own Dream Hurray!!



Read my previous blog on details on What is DayDream and Introduction.

Leave a Comment: