views:

306

answers:

2

I will try to explain a simple app scenario: My app goes right to a 'main view'. In this main view I have inserted a 'TextView' which displays current settings created by way of the PreferenceManager. For simplicities sake, let's say I have a checkbox in my settings. When I first start my app - the TextView on my main view shows my checkbox setting correctly (true). Now I go to the settings menu, it pops-up, and then I change it to false. I go back to the main view and...no change. It still say's true even after I changed it to false. If I end the app and then re-start it - all is well and it shows my change.

Apparently the main view just stays in the background while I'm changing settings? How can I redraw or update the main view after I change settings?

+1  A: 

When you go into your preferences your current activity should be paused and the resumed when you go back (see the lifecycle diagram on lifecycle diagram on the android site). You should be able to trigger some kind of redraw from within onResume() I would think. That will allow the data on the page to repopulate. Some sort of invalidate() call would do it I guess.

Vagnerr
Thanks for your help, I will begin to look into this now - I appreciate your time!
Allan
I'm a beginner so I hope this isn't too difficult for me - (I'll take more help and examples from others too)
Allan
+1  A: 

You could implement OnSharedPreferenceChangeListener in your main Activity:

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    if (PREFKEY_OF_INTEREST.equals(key))
        updateSomethingInMainView();
}

and in onCreate() call:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
kostmo
Thank you everyone for helping me. That onResume did the trick!
Allan