سؤال

I am using GreenDao in my application and currently encountering an interesting problem.

Firstly I deleted an entity Item "A" (ID=1) and run it in transaction using runInTx() from DaoSession.

After deletion, my application goes back to list of items and expectedly found out my item is removed. Then I add a new item entity Item "B" into DB, when I went back to the list again using EntityDao.QueryBuilder().list() I found out entity Item "A" was listed again, not entity Item "B".

When I checked the DB, entity Item "B" was created using the same ID=1. Listing all Items seems to me will return cached entities.

I did the following DaoSession.clear() after delete, however it still results in cached deleted entity.

Anyone has any idea on this issue?

هل كانت مفيدة؟

المحلول

I found the solution to this problem.

The issue is that I was DaoSession.clear() inside delete activity, call activity.finish() then go back to list item activity.

It was clearly activity management issue as I designed each activity to have its own DaoSession. Each instance of DaoSession will contain session cache of GreenDao objects.

More information of GreenDao's session cache can be read here

So the solution is clearing List Item activity's DaoSession after delete activity is finished.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top