本帖最后由 zhgna0163 于 2012-04-06 15:10:57 编辑

解决方案 »

  1.   

    没有红色部分代码 你是如何看到cursor.getCount() = 0有红色部分代码 cursor.getCount() = 1 说明正确你使用地方可能有问题,把使用的方法多贴点代码
      

  2.   

    "回复1楼"没有红色部分代码 你是如何看到cursor.getCount() = 0在 cursor = this.getContentResolver().query(uri...)
    跟一句 system.out 就看到了 cursor.getCount() = 0刚又发现其实在
    ContentProvider部分的Cursor cursor = null;
    try{
    cursor = mDB.query(......)
    }
    catch(Exception e){}
    finally{关闭数据库代码}System.out.println("query cursor = "+cursor.getCount());
    try catch 代码块外面 检查cursor ,此时cursor 的 getCount() 已经变为 0 !!!难道 cursor 生命周期 出问题了?
      

  3.   

    cursor 在用完之前是不能关闭数据连接的吧
      

  4.   

    同意3楼,数据库连接关闭后,cursor就没了,应该是这个原因
      

  5.   


    正解,但是数据库什么时候关掉呢?不应该限制我什么时候使用cursor 吧?
    曾经试图MockCursor 但是太麻烦了.难道非要让我专门定义一个关闭数据库 uri ??
    有这么干的吗??
      

  6.   

    ContentProvider接口的返回类型明确规定是 Cursor 
    这个不能改.有没有什么办法既可以关掉数据库 又可以不限制使用 Cursor 使用时间(前提是保证这个Cursor 还是那一次查询的结果)的办法 ?