0

I have this code which allows me to set the current device wallpaper as my activitys background.

public void wallpaperBackground()
    {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();

        View root = findViewById(R.id.home_view);
        root.setBackground(wallpaperDrawable);
    }

The problem is, if I change the wallpaper via settings it doesn't update on my app and I'm left with the previous wallpaper. How can I fix this?

user1353517
  • 300
  • 3
  • 10
  • 28
  • 1
    Just call this `wallpaperBackground()` method in `onResume()` in your activity. See also [Managing the Activity Lifecycle](http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle) – Jonas Czech Mar 16 '15 at 18:48
  • Thanks! why didn't I think of this. Doh! – user1353517 Mar 16 '15 at 18:53

1 Answers1

1

It is quite easy actually:

Just call your wallpaperBackground() method in onResume() in your activity.

This will automatically apply the correct wallpaper when the activity resumes after the user comes back from another app.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65