我的情况是这样的。我有一个 OrmLiteBaseActivity,那里有我的主菜单。当我按下一个按钮时,我进入“备份模式”,我想从我的网站下载一个备份 sqlite db。问题是,当我尝试上传文件时,我没有收到任何错误,但数据库不会更新,直到我关闭并重新打开软件。我希望更新是即时的。
我在我的 OrmLiteBaseActivity 上试过这样的东西:
case BACKUP_ID:
getHelper().close();
Intent i = new Intent(this, Backup.class);
this.startActivity(i);
return true;
我去备份活动,更新文件,然后我想回去,但我得到了这个错误:
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)
有什么我想念的吗?我假设每次打开新的 OrmLiteBaseActivity 时使用 OrmLiteBaseActivity 都会重新打开数据库。难道我做错了什么?