如何在Android中从App删除共享的首选项数据 [英] How to delete shared preferences data from App in Android

查看:91
本文介绍了如何在Android中从App删除共享的首选项数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为我的应用程序删除SharedPreferences数据?

How do I delete SharedPreferences data for my application?

我正在创建一个使用大量Web服务来同步数据的应用程序.出于测试目的,我需要在重新启动应用程序时清除一些SharedPreferences值.

I'm creating an application that uses a lot of web services to sync data. For testing purposes, I need to wipe out some SharedPreferences values when I restart the app.

推荐答案

要删除特定值,请执行以下操作:

To remove specific values: SharedPreferences.Editor.remove() followed by a commit()

要删除所有SharedPreferences.Editor.clear(),然后再删除commit()

To remove them all SharedPreferences.Editor.clear() followed by a commit()

如果您不关心返回值,而在应用程序的主线程中使用此返回值,请考虑改用apply().

If you don't care about the return value and you're using this from your application's main thread, consider using apply() instead.

这篇关于如何在Android中从App删除共享的首选项数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆