My situation is this. I have an OrmLiteBaseActivity where there is my main menu. When I press a button I go in “backup mode” and I want to download a backup sqlite db from my website.
The problem is that when I try to upload the file, I get no error but the db is not updated untill I close and reopen the software. I would like the update to be on-the-fly.
I’ve tried on my OrmLiteBaseActivity something like this:
case BACKUP_ID:
getHelper().close();
Intent i = new Intent(this, Backup.class);
this.startActivity(i);
return true;
The I go to the backup activity, update the file, then I want to go back but I got this error:
11-15 19:27:45.359: ERROR/DatabaseHelper(229): Getting connectionSource called after closed
11-15 19:27:45.359: ERROR/DatabaseHelper(229): java.lang.IllegalStateException
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getConnectionSource(OrmLiteSqliteOpenHelper.java:78)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getDao(OrmLiteSqliteOpenHelper.java:171)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at info.dierrelabs.h4m.ormliteinterface.DatabaseHelper.getPlayerDao(DatabaseHelper.java:159)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at info.dierrelabs.h4m.team.TeamList.onCreate(TeamList.java:20)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.os.Looper.loop(Looper.java:123)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at android.app.ActivityThread.main(ActivityThread.java:4363)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at java.lang.reflect.Method.invoke(Method.java:521)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-15 19:27:45.359: ERROR/DatabaseHelper(229): at dalvik.system.NativeStart.main(Native Method)
Is there something I’m missing? I assumed that using an OrmLiteBaseActivity would reopen the db everytime I open a new OrmLiteBaseActivity. Am I doing something wrong?
So I solved it. When the user presses the backup button, here’s what’s happening:
then I need to reopen this connection. You can actually do it like this (after I swapped sqlite files):
The class
Backupjust extendsActivity.