Prevent Live Wallpaper orientation change when an application is opened and orientation is changed?

情到浓时终转凉″ 提交于 2019-12-04 02:53:07

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.

Anirudha Agashe

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!