gpt4 book ai didi

android - 在 Gingerbread 上完美运行时,应用程序在 ICS 中的 Resume 上崩溃

转载 作者:行者123 更新时间:2023-11-29 14:53:27 24 4
gpt4 key购买 nike

我的主要 Activity (比如 A)提出了通过

从 ContactsContract 获取 ContactID 的 Intent
startActivityForResult(new Intent(Intent.ACTION_PICK, contactsContract.Contacts.CONTENT_URI),PICK_CONTACT);

返回 (onActivityResult(int reqCode, int resultCode, Intent data)) 时,我使用“数据”中的详细信息通过以下方式查询联系人

 if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
......

我的代码适用于 Android 2.x。然而,此代码在 ICS (Android 4.x) 中崩溃,同时恢复主要 Activity(A)。我不确定,这是否是由于已弃用的“managedQuery”所致。有人可以提供一些解决方案,我被卡住了,甚至无法找到导致错误的行,因为 Log cat 甚至没有显示错误行号。它只是说 原因:android.database.StaleDataException:试图在游标关闭后访问它。提前致谢乔希

刚完成游标的要求,我试过上面的代码。问题仍然存在。我的日志猫说如下

08-13 00:26:31.427: W/dalvikvm(3176): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-13 00:26:31.447: E/AndroidRuntime(3176): FATAL EXCEPTION: main
08-13 00:26:31.447: E/AndroidRuntime(3176): java.lang.RuntimeException: Unable to resume activity {com.desquare.sp/com.desquare.sp.SmartPadActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Looper.loop(Looper.java:137)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 00:26:31.447: E/AndroidRuntime(3176): at dalvik.system.NativeStart.main(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:75)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:144)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.CursorWrapper.requery(CursorWrapper.java:186)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performRestart(Activity.java:4505)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performResume(Activity.java:4531)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
08-13 00:26:31.447: E/AndroidRuntime(3176): ... 10 more

最佳答案

这听起来像是问题所在:

* android.database.staledataexception : Access closed cursor

You seem to be getting the cursors using managedQuery.

I had problems with restoring an application, which for some reason in Icecream Sandwich did not close the cursors properly. The fix was to do this for all cursors right after using them:

if (cursor != null && !cursor.isClosed()) {  
myActivity.stopManagingCursor( cursor );
cursor.close();
}

关于android - 在 Gingerbread 上完美运行时,应用程序在 ICS 中的 Resume 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com