清除数据从缓存中使用GreenDAO [英] Clear Data From Cache Using GreenDAO

查看:377
本文介绍了清除数据从缓存中使用GreenDAO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,有4 活动从活动开始1到4。

In my app, there are 4 Activities starting from activities 1 to 4.

数据库创作发生在活动1和值在活动2更新,活动3 etc.But当我使用完成(移回​​到活动)活动从3到活动2,它不会显示更新的值,因为缓存。(广东话能够显示更新后的值)

Database creation takes place in activity1 and values are updated in activities 2, activities 3 etc.But when i moves back to activities using finish() from activities 3 to activities 2 ,it wont shown the updated value because of cache.(Cant able to show the updated value)

我试过 daosession.clear(),但它不清除数据。

i tried daosession.clear() ,but it is not clearing the data.

因此​​,如何清除旧的缓存并使用重新加载数据 GreenDAO

So how to clear old cache and reload the data using GreenDAO.

在所有这些活动中,我使用单独的会话。看到样品code

In all these activities , i used separate session .See sample code

假设当前的活动是 CaptureLocationDetails

public static CaptureLocationDetails getInstance()
{
    return instance;
}

   openHelper = new DevOpenHelper(MyApplication.getInstances());
    //openHelper.openDatabase();
    db = openHelper.getWritableDatabase();
    daoMaster = new DaoMaster(db);

    daoSession = daoMaster.newSession();



-----

----


 daoSession.getUserDao().update(entity);

然后

的GetMap 类(下一个活动)

DevOpenHelper openHelper = new DevOpenHelper(MyApplication.getInstances());
    db = openHelper.getWritableDatabase();
    daoMaster = new DaoMaster(db);
    daoSession = daoMaster.newSession();

----

 upPackLinear.setOnClickListener(new OnClickListener() {

        @Override
          public void onClick(View v)
        {

            //DaoSession.this.clear();


            //daoSession.clear();
            finish();

            CaptureLocationDetails.getInstance().daoSession.clear();

        }
    });

但是,当我返回到 CaptureLocationDetails 类,它从缓存中加载值。

But when i returned back to CaptureLocationDetails class , it loads value from cache.

推荐答案

您还可以用两个方法做到这一点。

You can do it with 2 approaches.

请按照以下步骤。如有不明之处,您可以检查教程。

Follow the following steps. If confused, you may check this tutorial.


  1. 启动第二届活动使用 startActivityForResult()

  2. 覆盖的onActivityResult()在第1 活动。在那里,清除DB缓存和重新获取数据。

  3. 完成()在第2 通话活动,电话的setResult()

  1. start your 2nd Activity using startActivityForResult()
  2. Override the onActivityResult() in the 1st Activity. There, clear the DB cache and refetch the data.
  3. before finish() call in 2nd Activity, call setResult().

  • 清除数据库高速缓存和负载在在onStart数据()

这样每次活动显示时间,数据将被获取。这不是有效的,因为每一次你的活动进来前景,在onStart()被调用。

This way every time the Activity shows up, data will be fetched. It's not efficient because every time your Activity comes in foreground, onStart() is called.

这篇关于清除数据从缓存中使用GreenDAO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆