Development‎ > ‎Tutorials‎ > ‎

Live Wallpaper

A new feature of Android 2.1 is Live Wallpapers.
This tutorial shows how to make them.

A Live Wallpaper is a subclass of WallpaperService and an Engine inner class.
Optionally an Activity (for settings) can be added to the package.

In the manifest.xml file, add these elements inside the application tag
            android:name="android.service.wallpaper.WallpaperService" />
        android:resource="@xml/mylwp" />
And don't forget to set the ApiLevel to 7.

The xml resource specified in the meta-data of the service must point to the Activitiy.
The user can start the activity by selecting the settings button in the preview screen or directly in the wallpaper settings on the home screen.
To have the wallpaper change without restarting after changing the settings, the engine can implement the SharedPreferences.OnSharedPreferenceChangeListener interface to receive such changes.
Next, create the WallpaperService subclass called MyLWPService.
It must have an inner class which subclasses Engine in WallpaperService and an onCreateEngine method to return it.
public class MyLWPService extends WallpaperService {

    public Engine onCreateEngine() {
           return new MyLWPEngine();

    class MyLWPEngine extends Engine {


To get to the canvas, use the getSurfaceHolder method in WallPaperService and call lockCanvas from the holder.
Call the holder's unlockCanvasAndPost method when done drawing.

An example of how to draw to the canvas can be found in the samples directory of the android sdk