Search code examples
androidsharedpreferencesandroid-preferenceslive-wallpaperpreferenceactivity

Correct way of detecting preference changes in a live wallpaper?


I created a live wallpaper with a preference activity. Unfortunately, any time the user changes a setting the onSharedPreferenceChangeListener gets called. The listener calls some routines that are somewhat CPU intensive (reinitialize a large mesh) so it makes the preference activity sluggish. How can I call the listener only when the user exits the preference activity?


Solution

  • Maybe you should use onPause or onDestroy in your preferenceActivity to calculate your large mesh. Seems you just want to recalculate on changes on any attribute, so just set a flag in onPreferencesChanged and do your maths when activity is closed and your going back to liveWallpaper-View.

    Another way would be to start your calculation in a parallel thread, to let the preferenceActivity act as normal.