Android.Service.Dreams.DreamService Class
Extend this class to implement a custom dream (available to the user as a "Daydream").

See Also: DreamService Members

Syntax

[Android.Runtime.Register("android/service/dreams/DreamService", DoNotGenerateAcw=true)]
public class DreamService : Android.App.Service, Android.Views.Window.ICallback, IDisposable

Remarks

Extend this class to implement a custom dream (available to the user as a "Daydream").

  1. DreamService.OnAttachedToWindowUse this for initial setup, such as calling DreamService.SetContentView(Android.Views.View).
  2. DreamService.OnDreamingStartedYour dream has started, so you should begin animations or other behaviors here.
  3. DreamService.OnDreamingStoppedUse this to stop the things you started in DreamService.OnDreamingStarted.
  4. DreamService.OnDetachedFromWindowUse this to dismantle resources (for example, detach from handlers and listeners).

xml Example

 <service
     android:name=".MyDream"
     android:exported="true"
     android:icon="@drawable/my_icon"
     android:label="@string/my_dream_label" >

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

     <!-- Point to additional information for this dream (optional) -->
     <meta-data
         android:name="android.service.dream"
         android:resource="@xml/my_dream" />
 </service>
 

xml Example

 <dream xmlns:android="http://schemas.android.com/apk/res/android"
     android:settingsActivity="com.example.app/.MyDreamSettingsActivity" />
 

java Example

 public class MyDream extends DreamService {

     &#64;Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();

         // Exit dream upon user touch
         setInteractive(false);
         // Hide system UI
         setFullscreen(true);
         // Set the dream layout
         setContentView(R.layout.dream);
     }
 }
 

xml Example

 <service
     android:name=".MyDream"
     android:exported="true"
     android:icon="@drawable/my_icon"
     android:label="@string/my_dream_label"
     android:permission="android.permission.BIND_DREAM_SERVICE">
   <intent-filter>
     <action android:name=”android.service.dreams.DreamService” />
     <category android:name=”android.intent.category.DEFAULT” />
   </intent-filter>
 </service>
 

Dreams 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.

The DreamService lifecycle is as follows:

In addition, onCreate and onDestroy (from the Service interface) will also be called, but initialization and teardown should be done by overriding the hooks above.

To be available to the system, your DreamService should be declared in the manifest as follows:

If specified with the <meta-data> element, additional information for the dream is defined using the NoType:android/R$styleable;Href=../../../../reference/android/R.styleable.html#Dream element in a separate XML file. Currently, the only addtional information you can provide is for a settings activity that allows the user to configure the dream behavior. For example:

res/xml/my_dream.xml

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

To specify your dream layout, call DreamService.SetContentView(Android.Views.View), typically during the DreamService.OnAttachedToWindow callback. For example:

When targeting api level 21 and above, you must declare the service in your manifest file with the NoType:android/Manifest$permission;Href=../../../../reference/android/Manifest.permission.html#BIND_DREAM_SERVICE permission. For example:

[Android Documentation]

Requirements

Namespace: Android.Service.Dreams
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 17