简体   繁体   English

关于恢复Android活动的SQLite异常

[英]SQLite Exception on Resuming Android Activity

My app has a hierarchy of Activities, A -launches- B -launches- C 我的应用程序具有活动层次结构,A-launches-B -launches-C

In the third Activity 'C' I have a button. 在第三个活动'C'中我有一个按钮。

In the onClickListener of this button I launch an Intent as follows: 在这个按钮的onClickListener中,我按如下方式启动一个Intent:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(uri));
startActivity(intent);
//I don't call finish()

It brings up the phone dialling dialog fine. 它打开电话拨号对话框很好。 If I hit the back button at this point I get the "Sorry!" 如果我在此时按下后退按钮,我会收到“抱歉!” popup saying my app stopped unexpectedly. popup说我的应用程序意外停止了。 On hitting the "Force Close" button my app reverts to the Activity 'B' rather then the expected 'C' (Assuming no crash). 在点击“强制关闭”按钮时,我的应用程序恢复到活动'B'而不是预期的'C'(假设没有崩溃)。

Activity 'B' does use the SQL query shown in the exception however I don't know why it is causing the exception when I hit 'Back' as it has nothing to do with Activity 'C'. 活动'B'确实使用异常中显示的SQL查询但是当我点击'Back'时我不知道为什么它会导致异常,因为它与Activity'C'无关。 My database has been closed and I don't get an Leak warnings. 我的数据库已关闭,我没有收到泄漏警告。

In Activity 'B' the database is opened immediately prior to executing the query and closed afterward. 在活动'B'中,数据库在执行查询之前立即打开,之后关闭。 Struggling with this all day so would appreciate any comments. 整天苦苦挣扎,所以会感激任何评论。

 Uncaught handler: thread main exiting due to uncaught exception
 java.lang.IllegalStateException: mQuery SELECT islocal, packageid, Name, mapradius FROM categories WHERE islocal=? 1 
     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:162)
     at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:536)
     at android.app.Activity.performRestart(Activity.java:3740)
     at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3312)
     at android.app.ActivityThread.access$2600(ActivityThread.java:123)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:4370)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.database.sqlite.SQLiteMisuseException: library routine called out of sequence: handle 0x0
     at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
     at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:153)
     ... 13 more
ERROR/SemcCheckin(17282): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump

I just solved this exception in my app. 我刚在我的应用中解决了这个异常。 Not sure if the cause was the same as yours... 不确定原因是否和你的一样......

Activity A was performing a query JOIN on 2 tables in the database via a bridge table. 活动A通过桥接表对数据库中的2个表执行查询JOIN。 The records from that join were put into a ListView and when a user clicks a record, my app fires off Activity B. When you hit the back button on Activity B, resuming Activity A this exception happened. 来自该连接的记录被放入ListView中,当用户点击记录时,我的应用程序将触发活动B.当您点击活动B上的后退按钮时,恢复活动A会发生此异常。

The fix was to explicitly close the cursor (cur.close()) in Activity A when it was finished retrieving data. 修复是在完成检索数据时显式关闭活动A中的游标(cur.close())。 Before I was just closing the DB. 在我关闭数据库之前。

This DID NOT happen if Activity A did a basic query without a JOIN. 如果活动A在没有JOIN的情况下执行基本查询,则不会发生此DID。 So it seems when you join multiple tables and return in a cursor, the requery that the system performs on that open cursor when your task resumes generates this exception. 因此,当您连接多个表并返回游标时,系统在您的任务恢复时对该打开游标执行的重新查询会产生此异常。 You have to explicitly close the cursor so that the resume establishes a new one. 您必须显式关闭游标,以便简历建立一个新的。 Another factor that could have caused this is that my DB access in Activity A happens on a separate worker thread. 可能导致这种情况的另一个因素是我在活动A中的数据库访问发生在一个单独的工作线程上。

The problem turned out to be a concurrency issue relating to open connections to the database. 问题结果是与数据库的开放连接有关的并发问题。 Still not entirely sure about the root cause as I always closed my connections. 仍然不完全确定根本原因,因为我总是关闭我的联系。 Anyway, I created a single connection that is shared across all activities and the problem has gone away. 无论如何,我创建了一个在所有活动中共享的单一连接,问题已经消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM