每当我尝试添加此行时,它都会使我的应用程序崩溃。我没有把它放在正确的位置吗?
preferences.registerOnSharedPreferenceChangeListener(myActivity.this);
这是我的课
class Simulation extends View {
// I declare my program variables here
public Simulation(Context context) {
super(context);
// get the preferences
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context);
preferences
.registerOnSharedPreferenceChangeListener(myActivity.this);
String storedPreference = preferences.getString("nPref", "0");
}
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
Log.i(TAG, "preferences changed!");
}
}
谢谢!