質問

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?

役に立ちましたか?

解決

You shoud override onSharedPreferenceChanged to react to changed preference:

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

他のヒント

If PreferenceActivity is directly called from your main activity, a solution would be to start PreferenceActivity with the method startActivityForResult. This method allows to pass back some data from the activity which is launched to the activity which launched it. This means you will have to implement in your main activity the method onActivityResult.

If you choose this solution, check the article "Getting a Result from an Activity" on the official doc : http://developer.android.com/training/basics/intents/result.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top