How to close Objectbox Store and delete data files

Viewed 2542

I'v got an exception after I call put() with my data list.
I know that I closed the box before with a reason (deleteAllFiles() must be closed).
How should I open it again? As I see, dataBoxStore is not null after I closed it.

My code:

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();

dataBoxStore.close();
dataBoxStore.deleteAllFiles();

final Box<Data> areaLocationBox = dataBoxStore.boxFor(Data.class);
areaLocationBox.put(myList);

Exception:

 Caused by: java.lang.IllegalStateException: Store is closed
    at io.objectbox.BoxStore.checkOpen(BoxStore.java:261)
    at io.objectbox.BoxStore.beginTx(BoxStore.java:310)
    at io.objectbox.Box.getWriter(Box.java:107)
    at io.objectbox.Box.put(Box.java:389)
2 Answers
dataBoxStore.put(myList);

Throw the exception of Store is closed while and dataBoxStore is not null.

What I found is to initiate the boxStore again to use it:

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();

dataBoxStore.close();
dataBoxStore.deleteAllFiles();

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();
final Box<Data> areaLocationBox = dataBoxStore.boxFor(Data.class);
areaLocationBox.put(myList);
Related