11

I'm having an orientation issue with a Live Wallpaper that I wrote. Basically the canvas will rotate depending on the application opened above it. I tested this and realized that the onSurfaceChanged() method is firing when I return to the home screen from a previously opened application who's orientation was changed.

I suppose a better question would be, why does my Live Wallpaper Surface Change when an application is opened and it's orientation changed? Is there a way to prevent my Live Wallpaper orientation from ever changing? Thanks, hope that makes sense?

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
worked
  • 5,762
  • 5
  • 54
  • 79
  • Are you defining an orientation in the manifest? Or programmatically even? If not, the answers to [this](http://stackoverflow.com/q/2150287/404469) question should help. – gary Dec 23 '10 at 00:21
  • No Activity is ever used (besides the settings activity) in a Live Wallpaper. A LWP extends WallpaperService where in by it creates an instance of the Engine Class within the onCreateEngine() function. – worked Dec 23 '10 at 19:46
  • Can we get some more information? What are some of the apps that are causing this? Is the orientation permanent or just temporary until the main screen is being redrawn? Some apps such as the built-in camera actually force the screen to change orientation, but these changes are undone when the app is completed. – Music Monkey Nov 22 '12 at 09:53

2 Answers2

2

You can handle screen orientation from within the android.service.wallpaper.WallpaperService.Engine class with the following method:

public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height)

... just handle the event accordingly.

You CANNOT add android:configChanges nor android:screenOrientation to a WallpaperService! (Which you are using when creating a live wallpaper)

I would have added this as a comment to "Anirudha"'s answer, but I don't have enough reputation to do so.

Harry Silver
  • 397
  • 2
  • 11
1

Android application restarts the activity when the orientation changes. You can either use

  1. android:configChanges in your manifest. The activity is shut down and restarted by default, when a configuration change occurs at runtime, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
  2. use android:screenOrientatin = "portrait" or "landscape" it will force the app to run in the mode you specify. However it will not prevent the activity from being shut down and restarted.
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
Anirudha Agashe
  • 3,510
  • 2
  • 32
  • 47
  • hi, why is the activity forced to restart and how can one prevent that, in particular I need this for in the context of live wallpapers – Maysam Torabi Mar 12 '14 at 20:57