Example usage for android.database Cursor unregisterContentObserver

List of usage examples for android.database Cursor unregisterContentObserver

Introduction

In this page you can find the example usage for android.database Cursor unregisterContentObserver.

Prototype

void unregisterContentObserver(ContentObserver observer);

Source Link

Document

Unregister an observer that has previously been registered with this cursor via #registerContentObserver .

Usage

From source file:com.abcvoipsip.ui.favorites.FavLoader.java

/**
 * Helper function to take care of releasing resources associated with an
 * actively loaded data set.//from w  w  w.j av  a 2 s.  c  om
 */
protected void onReleaseResources(Cursor c) {
    if (c != null) {
        c.unregisterContentObserver(loaderObserver);
        c.close();
    }

    getContext().getContentResolver().unregisterContentObserver(loaderObserver);
}

From source file:com.csipsimple.ui.account.AccountsLoader.java

/**
 * Helper function to take care of releasing resources associated with an
 * actively loaded data set.//w w w . j  av a  2s  .com
 */
protected void onReleaseResources(Cursor c) {
    if (c != null) {
        c.unregisterContentObserver(loaderObserver);
        c.close();
    }
    if (loadStatus) {
        getContext().getContentResolver().unregisterContentObserver(loaderObserver);
    }
}

From source file:com.cattle.util.CursorPagerAdapter.java

/**
 * Swap in a new Cursor, returning the old Cursor. Unlike {@link #changeCursor(android.database.Cursor)}, the
 * returned old Cursor is <em>not</em> closed.
 *
 * @param newCursor The new cursor to be used.
 * @return Returns the previously set Cursor, or null if there was not one. If the given new Cursor
 *         is the same instance is the previously set Cursor, null is also returned.
 *//*from   w w w  . j av  a2s .c o  m*/
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == mCursor) {
        return null;
    }
    Cursor oldCursor = mCursor;
    if (oldCursor != null) {
        if (mChangeObserver != null) {
            oldCursor.unregisterContentObserver(mChangeObserver);
        }
        if (mDataSetObserver != null) {
            oldCursor.unregisterDataSetObserver(mDataSetObserver);
        }
    }
    mCursor = newCursor;
    if (newCursor != null) {
        if (mChangeObserver != null) {
            newCursor.registerContentObserver(mChangeObserver);
        }
        if (mDataSetObserver != null) {
            newCursor.registerDataSetObserver(mDataSetObserver);
        }
        mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        mDataValid = true;
        // notify the observers about the new cursor
        notifyDataSetChanged();
    } else {
        mRowIDColumn = -1;
        mDataValid = false;
        // notify the observers about the lack of a data set
        notifyDataSetChanged();
    }
    return oldCursor;
}

From source file:uk.co.senab.photup.util.CursorPagerAdapter.java

/**
 * Swap in a new Cursor, returning the old Cursor. Unlike
 * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
 * closed./* w ww  .j  a  v  a 2s. c o  m*/
 * 
 * @param newCursor
 *            The new cursor to be used.
 * @return Returns the previously set Cursor, or null if there was not one.
 *         If the given new Cursor is the same instance is the previously
 *         set Cursor, null is also returned.
 */
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == mCursor) {
        return null;
    }
    Cursor oldCursor = mCursor;
    if (oldCursor != null) {
        if (mChangeObserver != null)
            oldCursor.unregisterContentObserver(mChangeObserver);
        if (mDataSetObserver != null)
            oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }
    mCursor = newCursor;
    if (newCursor != null) {
        if (mChangeObserver != null)
            newCursor.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null)
            newCursor.registerDataSetObserver(mDataSetObserver);
        mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        mDataValid = true;
        // notify the observers about the new cursor
        notifyDataSetChanged();
    } else {
        mRowIDColumn = -1;
        mDataValid = false;
        // notify the observers about the lack of a data set
        notifyDataSetChanged();
    }
    return oldCursor;
}

From source file:com.niveales.library.utils.MyCursorAdapter.java

/**
 * Swap in a new Cursor, returning the old Cursor.  Unlike
 * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
 * closed./*from w  ww. ja v  a2 s  .c  o m*/
 *
 * @param newCursor The new cursor to be used.
 * @return Returns the previously set Cursor, or null if there wasa not one.
 * If the given new Cursor is the same instance is the previously set
 * Cursor, null is also returned.
 */
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == mCursor) {
        return null;
    }
    Cursor oldCursor = mCursor;
    if (oldCursor != null) {
        if (mChangeObserver != null)
            oldCursor.unregisterContentObserver(mChangeObserver);
        if (mDataSetObserver != null)
            oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }
    mCursor = newCursor;
    if (newCursor != null) {
        if (mChangeObserver != null)
            newCursor.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null)
            newCursor.registerDataSetObserver(mDataSetObserver);
        mRowIDColumn = newCursor.getColumnIndexOrThrow(id_field);
        mDataValid = true;
        // notify the observers about the new cursor
        notifyDataSetChanged();
    } else {
        mRowIDColumn = -1;
        mDataValid = false;
        // notify the observers about the lack of a data set
        notifyDataSetInvalidated();
    }
    return oldCursor;
}