【问题标题】:Adding multiple shared preferences keys to the flipper shared preferences plugin将多个共享首选项键添加到鳍状肢共享首选项插件
【发布时间】:2021-10-13 15:32:11
【问题描述】:

我想知道如何在 Flipper 共享首选项查看器插件中显示多个共享首选项键。 KEY_FOOKEY_BARKEY_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()
         }
     }

}

【问题讨论】:

    标签: android sharedpreferences flipper fbflipper


    【解决方案1】:

    在检查 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()
             }
         }
    
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多