Android getContentResolver (). notifyChange () does not restart my bootloader

codes:

First my uris

public static final String PACKAGE    = "my.url.contentprovider";

public static final String TABLE_NAME = "NetworkTransaction";

public static final String AUTHORITY  = PACKAGE + ".NetTransContentProvider";

public static final Uri BASE_URI = Uri.parse("content://"+AUTHORITY);

public static final Uri CONTENT_URI_ANY_OBSERVER  = Uri.withAppendedPath(BASE_URI,TABLE_NAME+"/*");

public static final Uri CONTENT_URI_FIND_BY_ID  = Uri.withAppendedPath(BASE_URI,TABLE_NAME+"/FIND/ID");

public static final Uri CONTENT_URI_INSERT_OR_REPLACE_BY_ID    = Uri.withAppendedPath(BASE_URI,TABLE_NAME+"/INSERT/REPLACE/ID"); 

public static final Uri CONTENT_URI_INSERT_BY_ID   = Uri.withAppendedPath(BASE_URI,TABLE_NAME+"/INSERT/ID"); 

and my loader from operation code:

@Override
protected void onResume() {
    super.onResume();
getSupportLoaderManager().restartLoader(NET_TRANS_LOADER_ID,mBundle,this).forceLoad();

}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
    Uri uri = null;
    CursorLoader cl=null;
    switch (id) {
    case NET_TRANS_LOADER_ID:
        uri = NetTransContentProvider.CONTENT_URI_FIND_BY_ID;
        cl  = new CursorLoader(ChoosingUserNameActivity.this, uri, NetTransDbUtils.allColumns,
                NetTransDbUtils.COLUMN_ID + " = ? ",
                new String[]{String.valueOf(bundle.getLong(EXTRA_TRANSACTION_ID,-1))}, null);

        break;
    default:
        break;
    }
    return cl;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    final int loaderId = loader.getId();
    switch (loaderId) {
    case NET_TRANS_LOADER_ID:
        if(mTransactionId != null){
            NetTrans netTrans = NetTransDbUtils.cursorToNetTrans(cursor);
            if(netTrans != null && netTrans.getStatus() != null 
                                && !netTrans.getStatus().equals(NetTrans.STATUS_PENDING)){
                EventBus.getDefault().post(new NetTransMsg(true, mTransactionId, netTrans.getMessage()));
            }
        }
        break;
    default:
        break;
    }
}

and at startup, which runs on ExecutorServicein a running service, I call

mContext.getContentResolver().insert(NetTransContentProvider.CONTENT_URI_INSERT_OR_REPLACE_BY_ID, cv );

the entered value, but the bootloader is not called up:

@Override
public Uri insert(Uri uri, ContentValues values) {
    int uriType = sUriMatcher.match(uri);
    switch (uriType) {

    case INSERT_OR_REPLACE_BY_ID:
        mDatabase.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        break;

    case INSERT_BY_ID:
        mDatabase.insert(TABLE_NAME, null, values);
        break;

    default:
        break;
    }

    getContext().getContentResolver().notifyChange(CONTENT_URI_ANY_OBSERVER, null);
    return null;
}
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,String sortOrder) {
        Cursor cursor = mDatabase.query(TABLE_NAME,projection,selection, selectionArgs, null, null, null);
        cursor.setNotificationUri(getContext().getContentResolver(), CONTENT_URI_ANY_OBSERVER);
        return cursor;
    }

my problem getContext().getContentResolver().notifyChange(CONTENT_URI_ANY_OBSERVER, null);with the insert method cannot restart my bootloader.


UPDATE

I created a project, you press the button, a new object NetTransis created and written to the database, then the stream sleeps 5000 ms and overwrites this value (to simulate the network). but after this, the bootloader dose does not resume. Where is my mistake?

+4
2

, , CONTENT_URI_ANY_OBSERVER, CONTENT_URI_FIND_BY_ID, .

  • -, CONTENT_URI_ANY_OBSERVER CONTENT_URI_FIND_BY_ID. , "CONTENT_URI_ANY_OBSERVER" `CONTENT_URI_FIND_BY_ID ' .

  • -, true notifyDescendants .

Android - (, , UriMatcher) . , , /* CONTENT_URI_ANY_OBSERVER, . , my.url.contentprovider/NetworkTransaction "" my.url.contentprovider/NetworkTransaction/INSERT/REPLACE/ID, my.url.contentprovider/NetworkTransaction/*.

1

, , . , . , , . NetTransDbUtils.cursorToNetTrans(cursor) , CursorLoader .

: close cursor.close() NetTransDbUtils.cursorToNetTrans(cursor); .

+6

Uris :

public static final Uri CONTENT_URI_ANY_OBSERVER = Uri
        .parse(BASE_URI + "/" + TABLE_NAME);
public static final Uri CONTENT_URI_FIND_BY_ID = Uri
        .parse(BASE_URI + "/" + TABLE_NAME + "/FIND/ID");
public static final Uri CONTENT_URI_INSERT_OR_REPLACE_BY_ID = Uri
        .parse(BASE_URI + "/" + TABLE_NAME + "/INSERT/REPLACE/ID");
public static final Uri CONTENT_URI_INSERT_BY_ID = Uri
        .parse(BASE_URI + "/" + TABLE_NAME + "/INSERT/ID");

RestService :

private Handler mHandler;

@Override
public void onCreate() {
    ...
    mHandler = new Handler();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    ...
    mHandler.post(task);
    ...
}
0

All Articles