How to avoid pausing android live wallpaper while settings activity is open when using GLSurfaceView

StackOverflow https://stackoverflow.com/questions/4469267

문제

I am writing a 3d live wallpaper for android using the famous GLSurfaceView wrapper (http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers)

When i open the preference screen to change wallpaper settings, the settings are displayed as transparent over my wallpaper preview. This is good because it lets me preview the settings changes I make. This works great, except for one problem: The live wallpaper is paused as long as the settings are on top of it!

How can i avoid my wallpaper pausing?

도움이 되었습니까?

해결책

I came up with a workaround which could be useful, depending on how your wallpaper functions...

In my settings activity, whenever the user makes a change (e.g. moves a slider, checks a checkbox), I broadcast an Intent with the relevant settings information.

In the live wallpaper's onCreate method, I dynamically register a BroadcastReceiver to receive these settings events. I unregister this receiver in onDestroy.

When receiving a settings broadcast, I make the wallpaper draw a single frame with the new settings. As the settings activity is transparent, this immediately gives the user an idea of what the wallpaper will look like with the chosen settings.

Similarly, using this approach, you could schedule the wallpaper to animate for a few seconds after a settings change — or whatever is appropriate for your implementation.

다른 팁

I found this to be kinda annoying as well. I averted the issue altogether by simply calling finish() in my settings activity whenever a change is made. This allows for an instant, full preview of the wallpaper for the user. It only takes a click to go back into the settings to make another change and it makes for a rather nice user experience.

 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
       finish();
 }

I used this in my line of wallpapers. Here is an example:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top