简体   繁体   English

Xamarin C#加载程序示例?

[英]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 .. 这个问题是针对Xamarin Android C#的,但是如果有人可以在Java中提供帮助,我确定我可以将代码转换为..

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. 我试过使用内容观察器,但是它从未触发过onchange我试过在游标中使用内容观察器,但也没有发生onchange。

(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.. 文件Observer缺少db插入的原因是因为SQLite DB实际上是一个2-3文件对象..如果您观看“ Example.DB”,则可能会错过在Example.DB-shm或Example.DB上发生的插入-沃尔

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 这样做的问题是,它将导致执行多个OnChange()。因此,当对这样的文件查看器进行编码时,必须在处理调用的同时调用stopwatch()并随后将其打开

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 .. 拥有一个“全局变量”(C#家伙会骂我叫它)或静态var,让应用程序知道您已经忙于该事件,因此在上一次调用完成之前不要执行代码。 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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