Example usage for android.content EntityIterator close

List of usage examples for android.content EntityIterator close

Introduction

In this page you can find the example usage for android.content EntityIterator close.

Prototype

public void close();

Source Link

Document

Indicates that this iterator is no longer needed and that any associated resources may be released (such as a SQLite cursor).

Usage

From source file:edu.cens.loci.ui.PlaceViewActivity.java

public void onQueryComplete(int token, Object cookie, final Cursor cursor) {
    final ArrayList<Entity> oldEntities = mEntities;
    (new AsyncTask<Void, Void, ArrayList<Entity>>() {
        @Override/*  ww  w. j ava  2s. c o  m*/
        protected ArrayList<Entity> doInBackground(Void... params) {
            ArrayList<Entity> newEntities = new ArrayList<Entity>(cursor.getCount());
            EntityIterator iterator = Places.newEntityIterator(cursor);
            try {
                while (iterator.hasNext()) {
                    Entity entity = iterator.next();
                    newEntities.add(entity);
                }
            } finally {
                iterator.close();
            }
            return newEntities;
        }

        @Override
        protected void onPostExecute(ArrayList<Entity> newEntities) {
            if (newEntities == null) {
                // There was an error loading.
                return;
            }
            synchronized (PlaceViewActivity.this) {
                if (mEntities != oldEntities) {
                    // Multiple async tasks were in flight and we
                    // lost the race.
                    return;
                }
                mEntities = newEntities;
                mHasEntities = true;
            }
            considerBindData();
        }
    }).execute();
}