我想清除存储在共享首选项中的值 我正在使用此代码。如何删除android中的共享偏好值?
/* SharedPreferences myPrefs = this.getSharedPreferences("myPrefs",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = myPrefs.edit();
editor.clear();
editor.commit(); */
,但得到这个错误。
The method getSharedPreferences(String, int) is undefined for the type new View.OnClickListener(){}
私人OnClickListener logoBarListener =新OnClickListener(){ /* * (非的Javadoc) * * @see android.view.View.OnClickListener#的onClick(android.view.View) */ 公共无效的onClick(视图v){
if (v.getId() == R.id.img_bottom_home) {
showProgressBar(MainScreen.class);
} else if (v.getId() == R.id.img_bottom_basket) {
showProgressBar(ShopBasketGet.class);
} else if (v.getId() == R.id.img_bottom_notification) {
showProgressBar(Notification.class);
} else if (v.getId() == R.id.img_bottom_login) {
SharedPreferences myPrefs = getSharedPreferences("myPrefs",
MODE_WORLD_READABLE);
SharedPreferences.Editor editor = myPrefs.edit();
editor.clear();
editor.commit();
showProgressBar();
}
}
};
什么Shaiful说的是right.Try使用YourActivityName.this.getSharedPreferences( “myPrefs”,Context.MODE_PRIVATE); –
它也不起作用。 –