Android SDK OnSharedPreferenceChangeListener双回调

时间:2015-06-16 23:02:24

标签: android

代码:

public class SettingsActivity extends PreferenceActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(PreferencesChanged);
    }

    SharedPreferences.OnSharedPreferenceChangeListener PreferencesChanged = new
                SharedPreferences.OnSharedPreferenceChangeListener() {

            @Override
            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                    String key) {
                Toast.makeText(this, "changed", Toast.LENGTH_LONG).show();
              }
            };
}

答案:如果更改了任何选项(一次点击),文本会出现两次: - /这是正常的吗? “OnSharedPreferenceChangeListener”发送双回调吗?我如何防止双重回调?

0 个答案:

没有答案