- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试从共享首选项中删除数据。但我不能那样做。为了跟踪数据是否被删除,我使用了这段代码:
btnLogout.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
SharedPreferences prefs = getSharedPreferences(share_pref_file, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.remove(share_pref_file);
editor.clear();
editor.commit();
getApplicationContext().getSharedPreferences(share_pref_file, 0).edit().clear().commit();
String strJson = prefs.getString("jsondata","");
if(strJson != null)
{
Log.d("CLEAR", "cccccccccccccccccccccccccccc");
}
userFunctions.logoutUser(getApplicationContext());
Intent login = new Intent(getApplicationContext(),LoginActivity.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
// Closing dashboard screen
finish();
}
});
但在 logcat 窗口中,它每次都显示“cccccccccccccccccccccccccccc”值。
那么谁能帮我解决如何从共享首选项中删除/删除数据,以便在我单击“注销”按钮时它会删除所有存储的数据?提前致谢。
最佳答案
空字符串仍然是字符串(String("") != null
将返回 true)。试试这个:
if(!strJson.equals(""))
这首先假定空字符串永远不会成为您的 SharedPreferences
中的有效输入。
关于android - 从android中的共享首选项中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15757673/
我的组件的模板呈现一个列表: {{ m.name }} 组件为其设置动画 @Component({ selector: 'app-client-detail', tem
我在回收站 View 中为每个项目使用卡片 View ,但我在图片下方和上方有空白,我不确定如何,我需要摆脱它。这是每个项目的 xml 布局。
我有一个包含许多 float 子元素的 div。每个子项都是一个包含输入和标签的 div。在 Firefox 中它看起来不错,但在 IE7 中,一行的最后一项被换行以适合,而不是被移动到下一行。 Wr
我创建了一个包含三个按钮的 wxpython 框架,在将视频格式化到 wxpanel 上时出现问题 这就是我流式传输网络摄像头的方式。 #code for the stream of webcam t
我想为 ListView 中的每个项目创建一个 fragment ,因为我想分离出一些逻辑。我正在为每个项目使用 View 持有者。如果 View 不存在,我将创建一个新 fragment 并将其添加
我正在使用 Joda 解析 RSS 项中的 pubDate。日期必须采用 RFC-822 格式: http://feed2.w3.org/docs/error/InvalidRFC2822Date.h
我正在尝试为我的第一个项目提供一个在此循环中处于事件状态的类。但是第二个和第三个项目可能没有“事件”类。 @foreach ($news as $newsitem)
我是一名优秀的程序员,十分优秀!