简体   繁体   中英

Xamarin c# Loader example?

This problem is for Xamarin Android C# , but if someone can help in java I'm sure I can convert the code over ..

I'm trying to get some sort of automatic notification on a db that data has been inserted / deleted / etc.

There is outside apps that have access to the db in question, that insert / etc..

I've tried a file observer but it misses most of the inserts. I've tried using content observer but it never fires a onchange I've tried using the content observer inside a cursor but no onchange happens either.

(if I understand correctly they will only fire if I register a change occurred which is what I don't want)

Now I've discovered that loaders might be a solution.. They seem to have their own observer that fires when the data changes.

If this is also not an answer then perhaps a database trigger of some kind to notify my app the data was modified ?

I really need guidance here.. no idea how to properly implement a loader.. or if the content observer can be sufficient somehow with some sort of auto trigger as such..

OK, So!

The reason that file Observer was missing db inserts is because a SQLite DB is actually a 2 - 3 file object .. if you watch "Example.DB" then you can miss insert that can happen on Example.DB-shm or Example.DB-wal..

The fix to this, and its not a great fix, is to instead watch the folder ..

doing this will catch all inserts/deletes ..

The problem with this is that it will cause multiple OnChange() 's to execute.. So when coding a file observer like this, you have to either call the stopwatch() while you process the call and switch it on afterwards

OR

Have a "Global Variable" (C# guys are gonna swear at me for calling it that) or static var that lets the app know that you are already busy on the event so don't execute the code till the previous call has been completed ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM