- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的项目中实现 Jetpack Datastore。我正在使用 apha-01
版本并且代码运行良好。然后我在 Gradle 文件中看到有一个新版本,所以我将其更新为 alpha-03
.
启动我的应用程序后,我遇到了另一个问题。我发现在alpha-03
中没有找到Proto库版本所以我回滚到版本 alpha-01
.另外,我试过 alpha-02
.从那以后,我遇到了以下错误:
Process: com.montymobile.sands, PID: 19928
java.io.IOException: /data/user/0/com.montymobile.sands/files/datastore/sns_preferences.preferences_pb.tmp could not be renamed to /data/user/0/com.montymobile.sands/files/datastore/sns_preferences.preferences_pb
at androidx.datastore.SingleProcessDataStore.writeData$datastore_core_release(SingleProcessDataStore.kt:304)
at androidx.datastore.SingleProcessDataStore.transformAndWrite(SingleProcessDataStore.kt:282)
at androidx.datastore.SingleProcessDataStore$actor$1.invokeSuspend(SingleProcessDataStore.kt:165)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
我注意到发生这种情况是因为我一个接一个地保存了两个不同的 key ,每个都在一个协程中。当我评论第二个 Action 时,它起作用了。
最佳答案
Screenshot of the sime UI 检查以下代码。
class DataStoreClass(private val context: Context) {
private fun dataStore(): DataStore<Preferences> = context.createDataStore("settings")
suspend fun <T> save(key: Preferences.Key<T>, value: T) {
dataStore().edit {
it[key] = value
}
}
suspend fun <T> read(key: Preferences.Key<T>, defaultValue: T): T {
val pre = dataStore().data.first()
return pre[key] ?: defaultValue
}
}
open class BaseActivity : AppCompatActivity() {
inline fun <reified T> getSavedValue(key: String, defaultValue:T): Any {
var savedValue = Any()
runBlocking {
val operation = async {
val savedStr = DataStoreClass(this@BaseActivity).read(preferencesKey(key),
defaultValue!!).let {
it
}
savedValue = savedStr
}
operation.await()
}
return savedValue
}
fun <T> saveDesiredValue(key: Preferences.Key<T>, value: T) {
runBlocking {
CoroutineScope(Dispatchers.IO).launch {
DataStoreClass(this@BaseActivity).save(key, value)
}.join()
}
}
}
class MainActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bnt = findViewById<Button>(R.id.btnSave)
val btnRead = findViewById<Button>(R.id.btnRead)
val key = findViewById<EditText>(R.id.key)
val etValue = findViewById<EditText>(R.id.etValue)
val value = findViewById<TextView>(R.id.value)
bnt.setOnClickListener {
saveDesiredValue(preferencesKey(key.text.toString()),etValue.text.toString())
saveDesiredValue(preferencesKey("test"), Random.nextInt(100))
}
btnRead.setOnClickListener {
value.text = "${getSavedValue(key.text.toString(),"")} " +
"${getSavedValue("test",0)}"
}
}
}
关于Android 数据存储区 IOException 无法重命名为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64883210/
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我已经完成了注册页面,并且运行顺利。 现在我需要弄清楚登录部分。我想要它,所以一旦用户登录,它就会将他们带到私有(private)页面,只有登录的用户才能看到。 它不需要针对每个用户进行个性化设置,只
出于个人好奇心,我目前正在学习区 block 链的工作原理。我正在学习这门类(class),现在我已经使用网络套接字设置了点对点连接。区 block 链应用程序的多个实例现在可以使用这些套接字运行并相
我读过: The blockchain database isn’t stored in any single location, meaning the records it keeps are t
Closed. This question needs to be more focused。它当前不接受答案。 想要改善这个问题吗?更新问题,使它仅关注editing this post的一个问题。
如果我在区块链中进行交易,是否只有在将交易添加到区块链后才会进行比特币转账?如果是这样,挖掘区块可能需要时间,并且无法进行紧急付款。那么这不是区块链的劣势吗? 最佳答案 如果您不重视能够在没有第三方(
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题
根据我的理解,我读到的关于区 block 链的所有内容都表明,即使在私有(private)区 block 链上,每个参与者都可以查看所有交易。我看到它提到区 block 链的一个用例可能是共享医疗数据
服务器正在发送消息时,如何阻止连接到服务器的一个IP地址。我的发送消息选项程序如下所示。 private void buttonSendMsg_Click(对象发送者,EventArgs e) {
iam正在hadoop apache 2.7.1上工作 和iam添加大小不超过100 Kb的文件 所以如果我将块大小配置为1 mb或默认值是 128兆字节 不会影响我的文件,因为它们只会保存在一个块中
我有一个docker-compose文件here。我可以连接到7051并注册我的chaincode客户端,但是当我尝试连接到localhost:7050时,我得到一个错误,该错误在使用curl测试时如
从数据类型来看,区 block 链是单链表吗?因为每个 block 都使用哈希引用前一个 block 。 或者它是某种树? 最佳答案 区 block 链表示为单链表的方式。每个 block 都有前一个
我无法理解给定代码片段的 hashcode() 部分。 我尝试过搜索它,但我无法弄清楚。 this.hash = Arrays.hashCode(new Integer[]{data.has
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
我正在通过一些在线示例学习区 block 链。我有这个高级代码,我用以前的哈希创建一个新 block ,然后向它添加一个事务,然后生成 block 的困难哈希(有 8 个前导零) Block blo
我们有一个包含一些数字商品的网站。从那里购买的用户需要用 BTC 购买一些信用。在他购买信用卡后,脚本必须将他用 BTC 购买的货币 (USD) 数量加载到他的账户中。 所以这里我们有 HTML 表单
我目前正在使用 enumerateObjectsUsingBlock block 在 subview 下进行枚举,我怎样才能确定 block 的完成? 下面是区 block 内容 [self.view
我通常将显示 block 放在链接上,以使按钮的所有 div 都处于事件状态,而不仅仅是文本。但在这种情况下,我需要在 ul li 中使用 display:inline-block 我认为这会禁用其他
我正在尝试创建付款账单并通过电报机器人发送给我的客户:我正在使用区 block 链 API V2-https://blockchain.info/api/api 接收。我的代码是: xpub='***
有个面试题:区 block 链和不可变链表有什么区别? 我回答他们是相同的技术,然后没有通过测试。请纠正我的错误。 最佳答案 链表中的每一项通常通过指针或内存地址指向链表中的下一项。 区 block
我是一名优秀的程序员,十分优秀!