0
votes

I am currently using objectbox via koin dependency injection within my android app. It works fine however i need to re-initialise my DI and so i need to destroy the boxStore before. This is because i initialise the box via DI and if i do not destroy the current BoxStore I cannot create a new one.

I've found a similar post How to close Objectbox Store and delete data files however it hasn't solved my issue.

I have tried calling deleteAllFiles however i am getting an error.

        BoxStore.deleteAllFiles(context, (BoxStoreBuilder.DEFAULT_NAME))

        BoxStore.deleteAllFiles(context, null)

I am getting the error message:

java.lang.IllegalStateException: Cannot delete files: store is still open

this is on the line of code mentioned above. Any suggestions would be very helpful

2

2 Answers

0
votes

solution:

i had to access each of my boxes individually and delete them one at a time.

fun clearAll(){
    firstBox.box.removeAll()
    secondBox.box.removeAll()
    ....... 
}


fun closeAll(){
    firstBox.box.close()
    secondBox.box.close()
    ....... 
}
0
votes

You can just close the boxStore and then delete all files:

boxStore.close();
boxStore.deleteAllFiles();

There's also a static method for deleting all the files ( if you want to delete all files before you open boxStore )

It's the most efficient way.

Ref: https://github.com/objectbox/objectbox-java/issues/317