Android - Can SQLite Cursor's be used after closing the database?

前端 未结 3 1808
广开言路
广开言路 2021-02-07 10:11

First of all, correct me if I\'m wrong, but if you close a database connection, you can\'t use the Cursor you got from it, correct?

db.open();
Cursor c = db.quer         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 10:48

    First of all, correct me if I'm wrong, but if you close a database connection, you can't use the Cursor you got from it, correct?

    Correct.

    So is it there any way to use the Cursor after closing the database?

    I don't think so. I always closed the database when I'm done with the Cursor, even if I pass the cursor to another Cursor object.

    Like is there any way to pass it elsewhere and use it kinda like an object?

    Create method that will return cursorobject; and use the method wherever you need it. (Also create method that will close db after you are done)

    Or do you always have to leave the database connection open until you are done with the cursor?

    Otherwise the cursor will screw up.

提交回复
热议问题