I need to show some data from server. There are several fragments where items can be displayed, so it is not easy to mantain updates. I decided to cache data in DB and use ContentProvider to access it. But I have a strange issue.

Initially, there is no data in my database. I create `CursorLoader` and set `CursorAdapter` as adapter to `ListFragment`. Then I receive something from server and insert several records. I supposed Loader to be automatically notified about them and reload data. But nothing happens, and ListFragment stays empty.

The other strange thing related. I've wrote some code to add ActionBar menu for this fragment. In this situation it `onCreateOptionsMenu` is not called (despite of `setHasOptionsMenu(true)` in `onCreate`) and menu not added. When DB already has some data, it works normally.

It seems that something broken inside the `Fragment`, but there is nothing about this in logs. What do you think, what I am doing wrong?

Here is sample fragment, that works like this:

```
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.MenuInflater;

public class FeedFragment3 extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
    private static final int LOADER_ID = 1;

    private SimpleCursorAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public void onResume() {
        super.onResume();
        getActivity().getActionBar().setTitle(R.string.feed_ab_title);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.feed, menu);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1, null,
            new String[] {"title"},
            new int[] {android.R.id.text1}
        );
        setListAdapter(mAdapter);

        getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        return new CursorLoader(getActivity(), Consts.getFeedContentUri(), null, null, null, null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        mAdapter.changeCursor(data);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        mAdapter.changeCursor(null);
    }
}

```

Here is a part of ContentProvider. I suppose that calling `notifyChange` in `insert` and `setNotificationUri` in `query` make ContentProvider notified about changes. May be it is not enough?

```
public class FeedContentProvider extends ContentProvider {
    ...

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        DPLog.it(TAG, "Query: [%s]", uri);

        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables("feed");
        qb.setProjectionMap(mProjectionMap);

        Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        DPLog.it(TAG, "insert: [%s]", uri);

        String tableName = mTableNamesForCode.get(mUriMatcher.match(uri));
        mDb.getWritableDatabase().insert(tableName, null, values);

        getContext().getContentResolver().notifyChange(uri, null);

        return uri;
    }

    ...
}

```

Opening fragment in Activity:

```
private void openFeedFragment() {
    mFeedFragment = new FeedFragment3();
    showRootFragment(mFeedFragment);
    updateFeed();
}

private void updateFeed() {
    mApi.requestFeed(
        new Response.Listener<FeedResponse>() {
            @Override
            public void onResponse(FeedResponse response) {
                Uri uri = PostsContract.getFeedContentUri();
                Set<Long> existingIds = getPostIds(uri);

                ArrayList<ContentProviderOperation> operations = createMergeOperations();

                try {
                    getContentResolver().applyBatch(PostsContract.AUTHORITY, operations);
                } catch (RemoteException e) {
                    ...
                } catch (OperationApplicationException e) {
                    ...
                }
            }
        },
        null
    );
}

```

Logs when creating Fragment

```
03-21 19:12:35.041  22005-22344/com.app D/app.ContentProvider﹕ Cursor size: [0] 03-21 19:12:35.061  22005-22005/com.app V/app.checkpoint-checkpoint﹕ com.app.ui.fragment.FeedFragment3.onLoadFinished (FeedFragment3.java:60)
03-21 19:12:36.012  22005-22066/com.app D/app.API﹕ Request 'feed' finished
03-21 19:12:36.092  22005-22066/com.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1417K, 11% free 12805K/14256K, paused 25ms, total 25ms
03-21 19:12:36.122  22005-22005/com.app I/app.ContentProvider﹕ Query: [content://com.app.content.posts/feed] (PostsContentProvider.java:59)
03-21 19:12:36.122  22005-22005/com.app D/app.ContentProvider﹕ Cursor size: [0] (PostsContentProvider.java:78)
03-21 19:12:36.142  22005-22005/com.app I/app.ContentProvider﹕ insert: [content://com.app.content.posts/feed] (PostsContentProvider.java:97)
03-21 19:12:36.262  22005-22005/com.app D/app.ContentProvider﹕ Inserted id: [1] (PostsContentProvider.java:102)
...
03-21 19:12:37.453  22005-22005/com.app D/app.ContentProvider﹕ Inserted id: [21] (PostsContentProvider.java:102)
03-21 19:12:37.453  22005-22348/com.app I/app.ContentProvider﹕ Query: [content://com.app.content.posts/feed] (PostsContentProvider.java:59)
03-21 19:12:37.453  22005-22348/com.app D/app.ContentProvider﹕ Cursor size: [21] (PostsContentProvider.java:78)
03-21 19:12:37.463  22005-22073/com.app I/app.ContentProvider﹕ Query: [content://com.app.content.posts/feed] (PostsContentProvider.java:59)
03-21 19:12:37.463  22005-22073/com.app D/app.ContentProvider﹕ Cursor size: [21] (PostsContentProvider.java:78)
03-21 19:12:37.463  22005-22005/com.app V/app.checkpoint-checkpoint﹕ com.app.ui.fragment.FeedFragment3.onLoadFinished (FeedFragment3.java:60)

```