Closed gorodechnyj closed 8 years ago
I have the problom
By the way, the "selection and selectionargs" seems no work in cursorLoader.
@sp958857 @agrosner I have created custom CursorLoader which works with current version of DBFlow, and also gets notified of content Uri changes. https://gist.github.com/gorodechnyj/cd357d1479111697637e
One can use it like this:
public class UserStatusListLoader extends CursorLoader {
public UserStatusListLoader(Context context) {
super(context,
UserStatus.CONTENT_URI,
SQLite.select().from(UserStatus.class).orderBy(UserStatus_Table.count_used, false));
}
}
and later just return new UserStatusListLoader(YourActivity.this);
from onCreateLoader
method.
This class is just a copy of Android's CursorLoader class, adapted to DBFlow Query. Also earlier version of this code was introduced in @jiqimaogou pull request (https://github.com/Raizlabs/DBFlow/pull/135) but was never merged.
Personally I think this is the way we should use loaders with DBFlow.
@agrosner, I think you should make a special wiki page about how DBFlow can and should be used with CursorLoaders. And how Model instances could be restored from Cursor objects.
in develop
it now directly just calls down to native methods ...no conversions to worry about.
If I generate ContentProvider with DBFlow, and query model with CursorLoader like this:
return new CursorLoader(this, CustomModel.CONTENT_URI, null, null, null, CustomModel_Table._id + " DESC");
I get exception
java.lang.NullPointerException: Attempt to get length of null array at com.raizlabs.android.dbflow.runtime.BaseContentProvider.toProperties(BaseContentProvider.java:57) at ch.dotpay.db.DotpayDatabase_Provider.query(DotpayDatabase_Provider.java:136)
The exception is caused by reading length property of null projection field. But in Android SDK it is valid to specify null projection - it only indicates that CursorLoader should query all fields.