gpt4 book ai didi

java - 如何在Android上实现持久化队列

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:09 25 4
gpt4 key购买 nike

我的应用程序需要一个类似于队列的数据结构:将数据放入其中,从中接收数据,类似于 FIFO。对于数据,我现在指的是简单的字符串,稍后可能是更复杂的对象。问题是无论 Android 正在做什么,队列及其内容都应该是持久的。如果应用程序关闭并重新打开(甚至 Android 重启),队列应该具有与应用程序关闭之前相同的状态和数据。

我认为队列必须在引擎盖下使用某种存储,最好是设备的内部存储。也许你可以集思广益如何实现这一点。队列不一定必须在我的应用程序中运行,它也可以是某种松散耦合的后台服务,如果这在 Android 中是可能的(但对我的应用程序是私有(private)的)。

最佳答案

五月 squareup是一个不错的选择。

QueueFile is a lightning-fast, transactional, file-based FIFO. Addition and removal from an instance is an O(1) operation and is atomic. Writes are synchronous; data will be written to disk before an operation returns. The underlying file is structured to survive process and even system crashes and if an I/O exception is thrown during a mutating change, the change is aborted.

关于java - 如何在Android上实现持久化队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9033476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com