Reload Preferences in PreferenceActivity on Resume

后端 未结 2 1754
走了就别回头了
走了就别回头了 2021-01-04 20:56

In my app, some settings can possibly be changed while the PreferenceActivity is not open, and an issue I\'m running into is that addPreferencesFromResour

2条回答
  •  一向
    一向 (楼主)
    2021-01-04 21:48

    I had a similar problem. Failing to find a simple way to make my PreferenceActivity refresh itself, my solution was to add this to my PreferenceActivity:

    /**
     * Called when activity leaves the foreground
     */
    protected void onStop() {
        super.onStop();
        finish();
    }
    

    This will cause the Prefs screen to reload from SharedPreferences next time it is started. Needless to say, this approach won't work if you want to be able to go back to your preferences screen by using the back button.

提交回复
热议问题