hive icon indicating copy to clipboard operation
hive copied to clipboard

all box data is lost if app killed in background.

Open SebghatYusuf opened this issue 2 years ago • 7 comments

Steps to Reproduce

1- Initialize hive DB and open a box. 2- put some keys with values in the box. 3- after putting data into the box call await box.close(). 4- In Android show all open apps. and close the app window. 5- reopen the app, and all data is cleared now.

Code sample

    var box = await openBox('reports');
    reports.add(report);
    try {
      box.put('allreports', reports);
      await box.close();
    } catch (e) {
      printLog('error; $e');
    }

Version

  • Platform: iOS (15.0.4) , Android (12.0)
  • Flutter version: [e.g. 1.5.4]
  • Hive version: [e.g. 0.5.0]

SebghatYusuf avatar Jun 18 '22 07:06 SebghatYusuf

Having a similar issue on Windows desktop as well

andy98725 avatar Jun 18 '22 23:06 andy98725

This sounds like similar behavior to this issue. Consider reverting to 2.0.0 or testing which version introduced this issue?

andy98725 avatar Jun 19 '22 02:06 andy98725

@andy98725 as our deadline was close I just converted all my database to sqflite (SQlite). It was a huge thing but couldn't find any workaround for this issue with HiveDB.

SebghatYusuf avatar Jun 19 '22 08:06 SebghatYusuf

i switched too. first look is nice but fail recovery is basically not there. no way to force persist data no way to force reload data from disk. thats not good...

razfazz avatar Jun 20 '22 13:06 razfazz

Any suggestions or solution yet?

kechankrisna avatar Jul 18 '22 18:07 kechankrisna

@kechankrisna I personally switched to sqflite.

SebghatYusuf avatar Jul 18 '22 18:07 SebghatYusuf

Any suggestions or solution yet?

I do flush all boxes on AppLifecycleState changed to inactive. It works for me.

alexandrim0 avatar Jul 21 '22 09:07 alexandrim0

Any suggestions or solution yet?

I do flush all boxes on AppLifecycleState changed to inactive. It works for me.

How ?

Djihanegh avatar Nov 04 '22 16:11 Djihanegh

Any suggestions or solution yet?

I do flush all boxes on AppLifecycleState changed to inactive. It works for me.

How ?

https://github.com/alexandrim0/keyper/blob/main/lib/src/home/home_view.dart

alexandrim0 avatar Nov 07 '22 22:11 alexandrim0

Any solution here except the workaround?

burekas7 avatar Jan 26 '23 13:01 burekas7

Just to make this issue clear the workaround suggested by @alexandrim0 is currently the best solution to prevent losing data.

SebghatYusuf avatar Jan 26 '23 17:01 SebghatYusuf

@SebghatYusuf, can you reproduce if you do await box.put('allreports', reports) instead of just box.put('allreports', reports) in your example?

0ttik avatar Jan 31 '23 05:01 0ttik