本文整理汇总了Java中android.database.Cursor.unregisterContentObserver方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.unregisterContentObserver方法的具体用法?Java Cursor.unregisterContentObserver怎么用?Java Cursor.unregisterContentObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.unregisterContentObserver方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReleaseResources
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Helper function to take care of releasing resources associated with an
* actively loaded data set.
*/
protected void onReleaseResources(Cursor c) {
if(c != null) {
c.unregisterContentObserver(loaderObserver);
c.close();
}
if(loadStatus) {
getContext().getContentResolver().unregisterContentObserver(loaderObserver);
}
}
示例2: onReleaseResources
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Helper function to take care of releasing resources associated with an
* actively loaded data set.
*/
protected void onReleaseResources(Cursor c) {
if(c != null) {
c.unregisterContentObserver(loaderObserver);
c.close();
}
getContext().getContentResolver().unregisterContentObserver(loaderObserver);
}
示例3: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(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 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");
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();
// notifyDataSetInvalidated();
}
return oldCursor;
}
示例4: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == this.mCursor) {
return null;
}
Cursor oldCursor = this.mCursor;
if (oldCursor != null) {
if (this.mChangeObserver != null) {
oldCursor.unregisterContentObserver(this.mChangeObserver);
}
if (this.mDataSetObserver != null) {
oldCursor.unregisterDataSetObserver(this.mDataSetObserver);
}
}
this.mCursor = newCursor;
if (newCursor != null) {
if (this.mChangeObserver != null) {
newCursor.registerContentObserver(this.mChangeObserver);
}
if (this.mDataSetObserver != null) {
newCursor.registerDataSetObserver(this.mDataSetObserver);
}
this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
this.mDataValid = true;
notifyDataSetChanged();
return oldCursor;
}
this.mRowIDColumn = -1;
this.mDataValid = false;
notifyDataSetInvalidated();
return oldCursor;
}
示例5: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(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 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");
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();
notifyItemRangeRemoved(0, oldCursor.getCount());
}
return oldCursor;
}
开发者ID:vikasdesale,项目名称:News24x7-news-from-every-part-of-the-world,代码行数:37,代码来源:CursorRecyclerViewAdapter.java
示例6: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Swap in a new Cursor, returning the old Cursor. Unlike
* {@link #changeCursor(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 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");
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();
// notifyDataSetInvalidated();
}
return oldCursor;
}
示例7: unregisterContentObserver
import android.database.Cursor; //导入方法依赖的package包/类
@Override
public void unregisterContentObserver(ContentObserver observer) {
for (Cursor cursor : mCursors) {
cursor.unregisterContentObserver(observer);
}
}
示例8: testUpdateLeader
import android.database.Cursor; //导入方法依赖的package包/类
public void testUpdateLeader() {
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createLeaderValues();
Uri Uri = mContext.getContentResolver().
insert(LeaderContract.LeaderEntry.CONTENT_URI, values);
long leaderRowId = ContentUris.parseId(Uri);
// Verify we got a row back.
assertTrue(leaderRowId != -1);
Log.d(LOG_TAG, "New row id: " + leaderRowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(LeaderContract.LeaderEntry._ID, leaderRowId);
updatedValues.put(LeaderContract.LeaderEntry.COLUMN_USER_NAME, "Bob");
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor leaderCursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
leaderCursor.registerContentObserver(tco);
int count = mContext.getContentResolver().update(
LeaderContract.LeaderEntry.CONTENT_URI, updatedValues, LeaderContract.LeaderEntry._ID + "= ?",
new String[]{Long.toString(leaderRowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
tco.waitForNotificationOrFail();
leaderCursor.unregisterContentObserver(tco);
leaderCursor.close();
Cursor cursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI,
null,
LeaderContract.LeaderEntry._ID + " = " + leaderRowId,
null,
null
);
TestUtilities.validateCursor("testUpdateLeader. Error validating leader entry update.",
cursor, updatedValues);
cursor.close();
}
示例9: testUpdateFavoriteMovie
import android.database.Cursor; //导入方法依赖的package包/类
@Test
public void testUpdateFavoriteMovie() {
Context appContext = InstrumentationRegistry.getTargetContext();
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createTheWallValues();
Uri quoteUri = appContext.getContentResolver().
insert(FavoritesContract.FavoriteColumns.uriMovie, values);
long rowId = ContentUris.parseId(quoteUri);
// Verify we got a row back.
assertTrue(rowId != -1);
Log.d(LOG_TAG, "New row id: " + rowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(FavoritesContract.FavoriteColumns._ID, rowId);
updatedValues.put(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT, 250);
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = appContext.getContentResolver().update(
FavoritesContract.FavoriteColumns.uriMovie, updatedValues,
FavoritesContract.FavoriteColumns._ID + "= ?", new String[] { Long.toString(rowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
// If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie,
null, // projection
FavoritesContract.FavoriteColumns._ID + " = " + rowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateFavoriteMovie. Error validating quote entry update.",
cursor, updatedValues);
cursor.close();
}
示例10: testUpdateFavoriteTVShow
import android.database.Cursor; //导入方法依赖的package包/类
@Test
public void testUpdateFavoriteTVShow() {
Context appContext = InstrumentationRegistry.getTargetContext();
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createTheSimpsonsValues();
Uri quoteUri = appContext.getContentResolver().
insert(FavoritesContract.FavoriteColumns.uriTVShow, values);
long rowId = ContentUris.parseId(quoteUri);
// Verify we got a row back.
assertTrue(rowId != -1);
Log.d(LOG_TAG, "New row id: " + rowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(FavoritesContract.FavoriteColumns._ID, rowId);
updatedValues.put(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT, 500);
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriTVShow, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = appContext.getContentResolver().update(
FavoritesContract.FavoriteColumns.uriTVShow, updatedValues,
FavoritesContract.FavoriteColumns._ID + "= ?", new String[] { Long.toString(rowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
// If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriTVShow,
null, // projection
FavoritesContract.FavoriteColumns._ID + " = " + rowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateFavoriteTVShow. Error validating quote entry update.",
cursor, updatedValues);
cursor.close();
}
示例11: testUpdateFavoritePerson
import android.database.Cursor; //导入方法依赖的package包/类
@Test
public void testUpdateFavoritePerson() {
Context appContext = InstrumentationRegistry.getTargetContext();
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createMargotRobbieValues();
Uri quoteUri = appContext.getContentResolver().
insert(FavoritesContract.FavoriteColumns.uriPerson, values);
long rowId = ContentUris.parseId(quoteUri);
// Verify we got a row back.
assertTrue(rowId != -1);
Log.d(LOG_TAG, "New row id: " + rowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(FavoritesContract.FavoriteColumns._ID, rowId);
updatedValues.put(FavoritesContract.FavoriteColumns.COLUMN_KNOWNFOR_POSTER_PATH,
"/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg");
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriPerson, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = appContext.getContentResolver().update(
FavoritesContract.FavoriteColumns.uriPerson, updatedValues,
FavoritesContract.FavoriteColumns._ID + "= ?", new String[] { Long.toString(rowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
// If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriPerson,
null, // projection
FavoritesContract.FavoriteColumns._ID + " = " + rowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateFavoritePerson. Error validating quote entry update.",
cursor, updatedValues);
cursor.close();
}
示例12: testUpdateLocation
import android.database.Cursor; //导入方法依赖的package包/类
public void testUpdateLocation() {
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createNorthPoleLocationValues();
Uri locationUri = mContext.getContentResolver().
insert(LocationEntry.CONTENT_URI, values);
long locationRowId = ContentUris.parseId(locationUri);
// Verify we got a row back.
assertTrue(locationRowId != -1);
Log.d(LOG_TAG, "New row id: " + locationRowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(LocationEntry._ID, locationRowId);
updatedValues.put(LocationEntry.COLUMN_CITY_NAME, "Santa's Village");
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = mContext.getContentResolver().update(
LocationEntry.CONTENT_URI, updatedValues, LocationEntry._ID + "= ?",
new String[] { Long.toString(locationRowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
//
// Students: If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = mContext.getContentResolver().query(
LocationEntry.CONTENT_URI,
null, // projection
LocationEntry._ID + " = " + locationRowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateLocation. Error validating location entry update.",
cursor, updatedValues);
cursor.close();
}