Pregunta

i have one class for wallpaper WallpaperService#onCreateEngine( and in init i read the backgroundimage and color from sharedprefs.

Now if i start my app i set the choosable backgroundcolor and background.

I start the preview with

    Intent intent = new Intent(
            WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
    intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
            new ComponentName(this, CustomWallpaper.class));
    startActivity(intent);

its all fine in the preview put if i set the wallpaper i still see the old values, cause the class is not restarted.. (If i set another 3 party wallpaper and change settings and start mine its all ok)

Could someone give me a hint hwoto ?

¿Fue útil?

Solución

I have registered a BroadcastReceiver in my Engine:

IntentFilter filter = new IntentFilter("com.your.package.REFRESH");
receiver = new BroadcastReceiver() {
             @Override
             public void onReceive(Context context, Intent intent) {
                    draw();
              }
 };
 registerReceiver(receiver, filter);

And then, when you change the variables/drawables, call this, on the actual context:

context.sendBroadcast(new Intent("com.your.package.REFRESH"));

In the draw() method your redraw your wallpaper.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top