Note that there are some explanatory texts on larger screens.

plurals
  1. POCursorLoader not showing DB entires
    primarykey
    data
    text
    <p>I've got a <code>CursorLoader</code> in a <code>ListFragment</code> (that is inside a <code>ViewPager</code>) that queries a database. I have a content provider for that database, which I've verified works. </p> <p>The issue is this: when the app runs for the very first time a separate service calls a bulk <strong>insert</strong> in a <code>ContentProvider</code>:</p> <pre><code>public int bulkInsert(Uri uri, ContentValues[] values) { if(LOGV) Log.v(TAG, "insert(uri=" + uri + ", values" + values.toString() + ")"); final SQLiteDatabase db = openHelper.getWritableDatabase(); final int match = uriMatcher.match(uri); switch(match) { case SNAP: { db.beginTransaction(); for(ContentValues cv : values) { db.insertOrThrow(Tables.SNAP, null, cv); } db.setTransactionSuccessful(); db.endTransaction(); getContext().getApplicationContext().getContentResolver().notifyChange(uri, null); return values.length; } </code></pre> <p>The <code>CursorLoader</code> in the list fragment returns 0 rows though on the very first run (when the database gets created). If I close and restart the app then the <code>CursorLoader</code> works great and returns exactly what I need. I've tried to implement waiting via a handler, but it doesn't seem to help. Here is the <code>ListFragment</code> that utilizes the <code>CursorLoader</code>:</p> <pre><code>public class DataBySnapFragment extends ListFragment implements LoaderCallbacks&lt;Cursor&gt; { public static final String TAG = "DataBySnapFragment"; protected Cursor cursor = null; private DataBySnapAdapter adapter; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); Log.d(TAG, "RELOADING!!!!!"); onLoadDelay(); } }; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.d(TAG, "onActivityCreated"); adapter = new DataBySnapAdapter(getActivity(), R.layout.list_item_databysnap, null, new String[]{}, new int[]{}, 0); setListAdapter(adapter); getLoaderManager().initLoader(0, null, this); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_databysnap, null); return view; } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("error_workaround_1", "workaroundforerror:Issue 19917, http://code.google.com/p/android/issues/detail?id=19917"); } @Override public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) { CursorLoader cursorLoader = new CursorLoader(getActivity(), Snap.CONTENT_URI, null, null, null, Snap.DATA_MONTH_TO_DATE + " DESC LIMIT 6"); return cursorLoader; } @Override public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) { Log.d(TAG, "data rows: " + data.getCount()); if(data.getCount() &lt;= 0) { delayThread(); } else { adapter.swapCursor(data); } } @Override public void onLoaderReset(Loader&lt;Cursor&gt; loader) { adapter.swapCursor(null); } private void onLoadDelay() { getLoaderManager().initLoader(0, null, this); } private void delayThread() { new Thread() { public void run() { longTimeMethod(); handler.sendEmptyMessage(0); } }.start(); } private void longTimeMethod() { try { Thread.sleep(12000); } catch (InterruptedException e) { Log.e("tag", e.getMessage()); } } } </code></pre> <p>Can anyone let me know why this might be happening, or at least steer me in the right direction? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload