vendredi 29 mai 2015

CursorLoader and setUpdateThrottle

I'm building an application that leverages a CursorLoader, CursorTreeAdapter and LoaderManager to display information backed by a ContentProvider / SQLite database.

I'm inserting new rows in to the database in rapid succession (around every ~500 milliseconds) and would like to throttle the refresh of the list so it does't jump all over the place when I insert data.

Looking through the documentation there's a function on AsyncTaskLoader (which CursorLoader inherits from) - setUpdateThrottle

public void setUpdateThrottle (long delayMS)

Added in API level 11 Set amount to throttle updates by. This is the minimum time from when the last loadInBackground() call has completed until a new load is scheduled.

Parameters delayMS Amount of delay, in milliseconds.

Unfortunately, setting this to something like 5000 milliseconds doesn't seem to slow the reloads of the CursorTreeAdapter.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    ...
    CursorLoader cl = new CursorLoader(getActivity(),
            NotesContract.Notes.CONTENT_URI,
            projection,
            selection,
            selectionArgs,
            null);

    // setUpdateThrottle Doesn't seem to change anything
    cl.setUpdateThrottle(5000);
    return cl;
}

Any ideas on how to use this throttle function?

If this isn't the right way to use it, do you have any ideas on the best way to batch redraws using CursorLoader, CursorTreeAdapter and LoaderManager?

Aucun commentaire:

Enregistrer un commentaire