I don't want to be using:
onSharedPreferenceChanged
Because my Live Wallpaper is reinitialized every time something happens with a settings (making it crash, stack overflow!)
Instead I want to be calling the
onDestroy()
Methed from the settings during the main activity which has ATM:
SharedPreferences.OnSharedPreferenceChangeListener
I want to do this because it saves on performance & allows me to reinitialise my main class.
How would I go around doing this?
The OnSharedPreferenceChangeListener
and OnSharedPreferenceChanged()
are SUPPOSED to be called whenever a setting is changed? That's literally their purpose for being there, so when settings are changed their effects are seen immediately.
I'm not quite understanding why you want to call onDestroy()? This is only called when an application is going down... so I guess you could simply say:
this.finish(); // <- Will eventually call onPause(), onDestroy()
If you're looking to restart your application why not say finish you activity, and start a new one via:
StartActivity();
Thus you're completely re-initializing your activities with the new data?
I would however stick with your OnSharedPreferenceChanged()
and just try to find what is actually causing your errors, rather than abstracting the process.
[Update]
MainActivity.java
[...]
public static void DoSomething(){
// Do something in main, from any other?
}
[...]
PreferenceActivity.java
@Override
public void onDestroy(){
super.onDestroy();
MainActivity.DoSomething();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.