Alex Al
Alex Al

Reputation: 111

Android live wallpaper preview start activity when user clicks "set wallpaper"

I am developing a live wallpaper application and I have the following problem:
1) The user clicks on a button and the android live preview shows up using this code

Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(getBaseContext(), MyWallpaperService.class));
startActivityForResult(intent,WALLPAPER_CHANGED);

2) The live preview service shows up with the live wallpaper preview and the "Set wallpaper" button.

3) My problem is that I want to start a different activity after the preview if the user clicks "set wallpaper" and just return back if the user clicks the back button.I cannot find a way to catch this "set wallpaper" click. The onDestroy() method of the engine is called in both scenarios.

Would appreciate any help,thanks!

Upvotes: 1

Views: 1685

Answers (1)

demaksee
demaksee

Reputation: 1188

AFAIK There is no official API to determine whether user pressed "Set wallpaper", but you can use one trick that may help you:

  1. Create static boolean field in you Engine, i.e. 'startedInPreviewMode'

  2. Before redirecting app to wallpaper preview reset 'startedInPreviewMode'

  3. In onCreate() method of your Engine check isPreview() and remember result in 'startedInPreviewMode' - if current instance is not preview, then your engine is started in regular (not preview) mode - means user pressed "Set wallpaper"

  4. In onResume() method of you activity (where app is redirected to after closing wallpaper preview) check static boolean 'startedInPreviewMode' field and take any action that you want.

Upvotes: 1

Related Questions