So I am using ObjectBox with a library called LibGDX, which is a cross platform gaming library written in java. It works by loading what is like a Java applet inside a single Android Activity class, but all the work is done in the applet, and none in Android (apart from instantiating the Activity).
Because of this, my objectBox code is in Java and can't use a context. I therefore run
boxStore = MyObjectBox.builder().androidContext(this).build();
I am running the following code every time I create my DB object in the startup of my app.
private void createMyObjectBox() throws IOException {
FileHandle fileHandle = Gdx.files.local("objectstorefile");
if(!fileHandle.isDirectory()) {
fileHandle.mkdirs();
}
store = MyObjectBox.builder().directory(boxStoreDir).build();
}
I get this crash, if I start my app, then hit the home button instantly, then start it again. I think there is a residual MyObjectBox object still in existence, due possibly to the nature of Android and static objects etc, not being fully disposed of.
I'm not sure how I can test for this in order to avoid the error.