【问题标题】:Caching listview items when the user is offline用户离线时缓存列表视图项
【发布时间】:2016-09-19 05:15:43
【问题描述】:

我正在使用 Marvel api 来获取名称、图像和描述,但我希望用户也可以在离线模式下查看它...如何将它与数据库系统分开缓存? Lru缓存可以用来做吗?我只是想知道方法

【问题讨论】:

    标签: android listview caching


    【解决方案1】:

    借助TinyDB in ACtivity onPause() CallaBack 将您的 marvel arrayList 存储到 db

    ArrayList<Person> usersWhoWon = new ArrayList<Person>();
    tinydb.putListObject("allWinners", usersWhoWon);
    

    然后在onResume()回调中检查用户是否离线并从tinyDB中获取你的奇迹漫画列表

    new TinyDB(getApplicationContext()).getListObject(
                        PreferenceHelper.MY_CART_LIST_LOCAL, Marvel.class)
    

    【讨论】:

      猜你喜欢
      • 2016-12-16
      • 2012-11-12
      • 1970-01-01
      • 2015-08-14
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 2023-03-10
      相关资源
      最近更新 更多