Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Without declaring NotifyInsert/Update/Delete, insert, update and delete operations still invoke onLoadFinished #59

Closed
WalkerWalker opened this issue Sep 6, 2016 · 9 comments

Comments

@WalkerWalker
Copy link

WalkerWalker commented Sep 6, 2016

I guess it's a feature rather than a bug yet I feel it's quite odd.

I find that even without declaring @NotifyInsert, @NotifyBulkInsert, @NotifyUpdate and @NotifyDelete , the onLoadFinished (of a cursorLoader with query of certain URI) callback function still get invoked when insert, update and delete operations is performed to that URI.

I guess this is not a bug? It's just quite wired because supporting @NotifyInsert, @NotifyBulkInsert, @NotifyUpdate and @NotifyDelete somehow means that no notifying on data change without declaring these annotations.


I declare the URI with

    public static class Quotes {
        @ContentUri(
                path = Path.QUOTES,
                type = "vnd.android.cursor.dir/quote"
        )
        public static final Uri CONTENT_URI = buildUri(Path.QUOTES);


      @InexactContentUri(
                name = "QUOTE_ID",
                path = Path.QUOTES + "/*",
                type = "vnd.android.cursor.item/quote",
                whereColumn = QuoteColumns.SYMBOL,
                pathSegment = 1
        )
        public static Uri withSymbol(String symbol) {
            return buildUri(Path.QUOTES, symbol);
        }
    }

and query the database by defining a cursorLoader

        new CursorLoader(this, QuoteProvider.Quotes.CONTENT_URI,
                projection,
                selection,
                selectionArg,
                null);

and modify the database with

getContentResolver().delete(QuoteProvider.Quotes.withSymbol(symbol), null, null);

Then onLoadFinished gets called automatically without I declaring notifyDelete

@WalkerWalker
Copy link
Author

or is it true that the delete insert and update operation on certain URI guarantees to notify that exact URI and cursor returned by the query of the same URI will be notified (and thus invoke onLoadFinished).

I only need to declare @NotifyInsert, @NotifyBulkInsert, @NotifyUpdate and @NotifyDelete when other URIs are also affected?

@SimonVT
Copy link
Owner

SimonVT commented Sep 6, 2016

Yep, the Uri you use is notified by default. If you want some other behavior you use one of those annotations.

@WalkerWalker
Copy link
Author

Thanks!! Then can I say this part of the sample code is redundant?

@SimonVT
Copy link
Owner

SimonVT commented Sep 6, 2016

It's redundant, yes. Was probably added to test that it works :)

@WalkerWalker
Copy link
Author

Thanks!! One more question, is it true that adding the update/delete/insert annotations will notify those returned URIs in addition to the modified URI, right?

It's not replacing. It's declaring some extra uri getting notified plus the Uri by default.

@SimonVT
Copy link
Owner

SimonVT commented Sep 6, 2016

It replaces, but nothing's stopping you from returning the same Uri. I encourage you to check out the generated code :)

@WalkerWalker
Copy link
Author

I just did. I guess it's this chunk of code did the replace job, right?

I hope some helpful doc can be added because this @NotifyXxxxx annotations don't really explain themselves.

@SimonVT
Copy link
Owner

SimonVT commented Sep 6, 2016

Yes, that's the code that generates the ContentProvider. You can see the class it generates in build/generated/source/apt.

@WalkerWalker
Copy link
Author

Wow. I didn't know that!!!!! This is so helpful.

btw, it's app/build/source/apt in my android studio

@SimonVT SimonVT closed this as completed Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants