Search code examples
androidtextviewrefreshpreferenceactivitypreference

Refresh TextView on return from Activity


I'm writing a small application which saves your preferences. In the main activity, these preferences should be displayed. However, When returning from the PreferenceActivity Class, I still get the old values. The view only gets updated once I actually quit the app via the "Back" Button.

I've tried putting the setText command in the onResume() and onRestoreInstanceState() functions, but none actually refresh it.

What do I have to do to get it to refresh?


Solution

  • You shoud override onSharedPreferenceChanged to react to changed preference:

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
        //code
    }