Returning false in the callback for getAsync() still calls the callback
praneetloke opened this issue · 6 comments
OK. I'll try my best to describe this correctly. Right now, I am not sure if I am doing something wrong or if there is a bug in the async callback.
I have a scenario where I check for the existence of a certain item in the DB before I save it and hence I have a Query.One().getAsync() call. The callback given to the getAsync() part is returning false and yet it gets called again when I actually do save the item if it doesn't exist in the database. Moreover, since I save to the DB using saveAsync(), Sprinkles seems to call the callback anyway even when the record has not yet been saved and, thereby resulting in two records in the DB for a single save.
I guess a simple code sample to illustrate would be clearer:
private OneQuery.ResultHandler<Example> onExampleLoaded = new OneQuery.ResultHandler<Example>() {
@Override
public boolean handleResult (Example example) {
if (example == null) {
String something = "hello";
Example newExample = new Example(something);
newExample.saveAsync(new Model.OnSavedCallback() {
@Override
public void onSaved () {
Log.i(TAG, "Saved"); //this executes twice
}
});
}
//don't want to be notified of further changes
return false;
}
};
will look into it!
Thanks, dude!
I can't replicate this bug. And after looking through the code a couple of times i cannot understand why this is happening. So some questions.
- What android version?
- Are you using support library loaders or the standard loaders?
Android version is 4.2.2. I am using the support library (and, ABS as well) loaders. I am passing in the loader manager instance from getSupportLoaderManager().
Query.one(Example.class, "select * from Example where something=?", something).getAsync(getSupportLoaderManager(), onExampleLoaded);
I managed to replicate and fix a similar issue using the support loaders. Please comment here if your issue is still present after testing the new version (should be hitting maven central within the next couple hours)
wow!Thanks, man! I'll check it out and get back to you.