在获取memo的时候有一个根据Uri
获取Cursor的方法是用的Activity的方法:mCursor = managedQuery(mUri, PROJECTION, null, null, null);
public final Cursor managedQuery (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
This method is deprecated.
Use CursorLoader instead.
Wrapper around query(android.net.Uri, String[], String, String[], String) that gives the resulting Cursor to call startManagingCursor(Cursor) so that the activity will manage its lifecycle for you. If you are targeting HONEYCOMB or later, consider instead using LoaderManager instead, available via getLoaderManager().
Parameters
| uri | The URI of the content provider to query. |
|---|---|
| projection | List of columns to return. |
| selection | SQL WHERE clause. |
| selectionArgs | The arguments to selection, if any ?s are pesent |
| sortOrder | SQL ORDER BY clause. |
Returns
- The Cursor that was returned by query().
E/AndroidRuntime( 1051): java.lang.RuntimeException: Unable to resume activity {com.lenovo.leos.memowidget/com.lenovo.leos.notepad.NoteEditor}: java.lang.IllegalStateException: trying to requery an already closed cursor
E/AndroidRuntime( 1051): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2227)
E/AndroidRuntime( 1051): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2255)
E/AndroidRuntime( 1051): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1028)
E/AndroidRuntime( 1051): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1051): at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime( 1051): at android.app.ActivityThread.main(ActivityThread.java:4025)
E/AndroidRuntime( 1051): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1051): at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime( 1051): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/AndroidRuntime( 1051): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/AndroidRuntime( 1051): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1051): Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor
E/AndroidRuntime( 1051): at android.app.Activity.performRestart(Activity.java:4394)
E/AndroidRuntime( 1051): at android.app.Activity.performResume(Activity.java:4420)
E/AndroidRuntime( 1051): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2217)
E/AndroidRuntime( 1051): ... 10 more
W/ActivityManager( 124): Force finishing activity com.lenovo.leos.memowidget/com.lenovo.leos.notepad.NoteEditor
W/ActivityManager( 124): Activity pause timeout for ActivityRecord{40472ac8 com.lenovo.leos.memowidget/com.lenovo.leos.notepad.NoteEditor}
E/Launcher( 1029): onResume
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
如果使用query则单纯的将Cursor返回来,就不会出现上述异常了。
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query the given URI, returning a Cursor over the result set.
For best performance, the caller should follow these guidelines:
- Provide an explicit projection, to prevent reading data from storage that aren't going to be used.
- Use question mark parameter markers such as 'phone=?' instead of explicit values in the
selectionparameter, so that queries that differ only by those values will be recognized as the same for caching purposes.
Parameters
| uri | The URI, using the content:// scheme, for the content to retrieve. |
|---|---|
| projection | A list of which columns to return. Passing null will return all columns, which is inefficient. |
| selection | A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI. |
| selectionArgs | You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings. |
| sortOrder | How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered. |
Returns
- A Cursor object, which is positioned before the first entry, or null
See Also
以上就是如何解决pad记事本的从历史进入memo时出现上述异常的bug了。
本文介绍了解决Android应用中由于Cursor管理不当导致的异常问题。详细分析了使用managedQuery方法时可能出现的问题,并给出了替代方案,避免因Cursor被关闭而引发的错误。
4万+

被折叠的 条评论
为什么被折叠?



