A
A
Andrew2014-07-04 10:02:20
Android
Andrew, 2014-07-04 10:02:20

How to properly open and close cursor in android?

There was a question in what moment to close the cursor.
In the simplest case, we get a cursor, take data from it, and close the cursor. Everything is clear here.
Let's consider a more complicated case.
Suppose we have some Activity (let's call it Activity2), to which we will come from another Activity (let's call it Activity1) and after certain actions we will go to the next Activity (let's call it Activity3). There is a ListView on Activity2, which we need to fill with data from the database, for this we use CursorAdapter and Cursor.
1. The question arises at what point in the Activity2 life cycle should we create a cursor and close the cursor? In onResume and onPause?
2. CursorLoader can be used to create/close the cursor. When using it, the question arises at what point in the life cycle of the application / activity will the cursor be closed? In the onPause method? Or only when the entire application is closed.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question