android - 将多个共享首选项键添加到鳍状肢共享首选项插件
问题描述
我想知道如何在 Flipper Shared Preferences Viewer Plugin 中显示多个共享首选项键。KEY_FOO
, KEY_BAR
,KEY_BAZ
是共享首选项文件的字符串常量。
就像是
class App: Application() {
override fun onCreate() {
super.onCreate()
setupFlipper()
}
private fun setupFlipper() {
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {
val client = AndroidFlipperClient.getInstance(this)
client.addPlugin(InspectorFlipperPlugin(this, DescriptorMapping.withDefaults()))
client.addPlugin(
SharedPreferencesFlipperPlugin(applicationContext, KEY_FOO)
)
client.addPlugin(
SharedPreferencesFlipperPlugin(applicationContext, KEY_BAR)
)
client.addPlugin(
SharedPreferencesFlipperPlugin(applicationContext, KEY_BAZ)
)
client.start()
}
}
}
解决方案
检查 SharedPreferencesFlipperPlugin 的构造函数后。存在第二个选项,它采用 SharedPreferencesDescriptor 的列表。
下面的解决方案。
class App: Application() {
override fun onCreate() {
super.onCreate()
setupFlipper()
}
private fun setupFlipper() {
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {
val client = AndroidFlipperClient.getInstance(this)
client.addPlugin(InspectorFlipperPlugin(this, DescriptorMapping.withDefaults()))
val keys = mutableListOf(
KEY_FOO,
KEY_BAR,
KEY_BAZ,
)
var descriptors: List<SharedPreferencesFlipperPlugin.SharedPreferencesDescriptor> = keys.map {
SharedPreferencesFlipperPlugin.SharedPreferencesDescriptor(it, MODE_PRIVATE)
}
client.addPlugin(
SharedPreferencesFlipperPlugin(applicationContext, descriptors)
)
client.start()
}
}
}
推荐阅读
- python - Python安装pyPdf错误'utf-8'编解码器无法解码位置64的字节0x88
- excel - 在 excel 中从 CustomXmlPart 遍历 XML 时遇到问题
- scipy - 如何合并边界条件并从 scipy.interpolate.Bspline.basis_element 构建基函数,包括边界条件?
- javascript - Javascript在引号中加粗文本字符串
- javascript - 滚动条的禁用区域
- postgresql - 与 Azure VM 上的 PostgreSQL 数据库层失去连接
- java - 由缠绕规则创建的区域
- asp.net-core - 扩展 ASP.NET Core 中现有 AuthenticationScheme 的首选解决方案
- .net - 如何使用 WcfCoreMtomEncoder .NET 添加标头或请求正文
- authentication - 使用函数在 fetch 中检索令牌