jeudi 24 mars 2016

ContentProvider returns 0 rows when app launches first time

I have ContentProvider backed by SQLite database.

When I launch app for the first time (when it wasn't in RAM before), I get strange behaviour. Content provider returns 0 rows, but there is 100% some data stored in database (I use SQLite debugger to check). Here is my code:

@Override
    public List<Document> loadDocuments(String where, String[] whereArgs) {
        List<Document> documents = new ArrayList<>();
        Cursor cursor = context.getContentResolver().query(Contract.buildDocumentsListUri(), DatabaseHelper.DOCUMENTS_FIELDS, where, whereArgs, null);
        Log.d(LOG_TAG , "Cursor size: " + cursor.getCount());
        if (cursor.moveToFirst()) do {
            Document document = documentDatabaseConverter.fromCursor(cursor);
            documents.add(document);
        } while (cursor.moveToNext());
        return documents;
    }

Following my logs when first time launch, it always returns 0 count.

Maybe reason is in Context, but I tried different variants. Here is full class:

@EBean(scope = EBean.Scope.Singleton)
public class DatabaseDaoImpl implements IDatabaseDao {

    @RootContext
    Context context;

    @Bean(value = DocumentConverter.class)
    protected DatabaseConverter<Document> documentDatabaseConverter;

    @Override
    public List<Document> loadDocuments(String where, String[] whereArgs) {
        List<Document> documents = new ArrayList<>();
        Cursor cursor = context.getContentResolver().query(Contract.buildDocumentsListUri(), DatabaseHelper.DOCUMENTS_FIELDS, where, whereArgs, null);
        if (cursor.moveToFirst()) do {
            Document document = documentDatabaseConverter.fromCursor(cursor);
            documents.add(document);
        } while (cursor.moveToNext());
        return documents;
    }
}

Also here is entry in my Manifest file:

<provider
    android:name=".providers.DocumentsProvider"
    android:authorities="ua.pp.ssidit.entitiesdocs.providers.DocumentsProvider"
    android:exported="false"></provider>

Aucun commentaire:

Enregistrer un commentaire