什么是内容提供者?
What is content provider?
我只是按照 developer.android.com 中的教程创建同步适配器以提供程序功能 "synchronization between local db with server db",经过反复试验,我设法让它工作(onPerformSync 已成功调用)。
现在下一步要创建同步功能,根据我在几篇文章中阅读的内容,我需要创建一个 content provider
。我已经读过 https://developer.android.com/guide/topics/providers/content-provider-basics.html 但我仍然不明白它是如何工作的。
由此linkhttps://developer.android.com/guide/topics/providers/content-provider-basics.html,我脑子里提出了几个问题:
他们在说什么table
?他们是在谈论 sqlite table 还是一些 "another" table?
content://user_dictionary/words
这是什么uri?这是存储 sqlite 的 table 文件的 uri 吗?如果是,我怎么知道我的?我的意思是我创建的 sqlite 存储 table 在哪里?
根据我的阅读(如果我没记错的话),ContentProvider 就像一个存储库。他们有相同的功能吗?我已经使用 anko https://gist.github.com/mockiemockiz/a552a669d28a3c90c144bc1542b86a5e 创建了我的存储库,我可以使用该代码/将该代码转换为能够告诉同步适配器数据已更改的 ContentProvider 吗?
I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).
FWIW,SyncAdapter
不是特别受欢迎。
what table they are talking about?
单词 "table" 在该页面上出现了 40 次。我们无法知道这 40 个中的哪一个与您有关,并且他们以多种方式使用该术语。
what uri is this?
即Uri
指向user_dictionary
ContentProvider
中的一组数据("table")。
is this uri to table file where sqlite stored?
这是 ContentProvider
的开发者决定的。 ContentProvider
API 没有规定数据存储在哪里。它可以存储在 SQLite 中,或 JSON 文件中,或其他任何地方。 约定 表示 ContentProvider
公开的数据集合映射到 SQLite table 或视图,但这不是必需的。
if it's, how do I know mine?
如果您使用 user_dictionary
作为权限,您就知道它是您的 ContentProvider
(请参阅清单中 <provider>
元素中的 android:authorities
)。
I mean where did my sqlite store table that I created?
这取决于你。 ContentProvider
与 SQLite 无关,除非 你 编写代码将 ContentProvider
实现与 SQLite 联系起来。
ContentProvider just like a repository
不是真的,至少在我如何使用术语 "repository" 方面是这样。 ContentProvider
是一些数据存储机制的包装器,允许外部各方控制对该数据的访问。
can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?
那会比较难。这也是很少有开发者使用 SyncAdapter
.
的原因之一
我只是按照 developer.android.com 中的教程创建同步适配器以提供程序功能 "synchronization between local db with server db",经过反复试验,我设法让它工作(onPerformSync 已成功调用)。
现在下一步要创建同步功能,根据我在几篇文章中阅读的内容,我需要创建一个 content provider
。我已经读过 https://developer.android.com/guide/topics/providers/content-provider-basics.html 但我仍然不明白它是如何工作的。
由此linkhttps://developer.android.com/guide/topics/providers/content-provider-basics.html,我脑子里提出了几个问题:
他们在说什么
table
?他们是在谈论 sqlite table 还是一些 "another" table?content://user_dictionary/words
这是什么uri?这是存储 sqlite 的 table 文件的 uri 吗?如果是,我怎么知道我的?我的意思是我创建的 sqlite 存储 table 在哪里?根据我的阅读(如果我没记错的话),ContentProvider 就像一个存储库。他们有相同的功能吗?我已经使用 anko https://gist.github.com/mockiemockiz/a552a669d28a3c90c144bc1542b86a5e 创建了我的存储库,我可以使用该代码/将该代码转换为能够告诉同步适配器数据已更改的 ContentProvider 吗?
I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).
FWIW,SyncAdapter
不是特别受欢迎。
what table they are talking about?
单词 "table" 在该页面上出现了 40 次。我们无法知道这 40 个中的哪一个与您有关,并且他们以多种方式使用该术语。
what uri is this?
即Uri
指向user_dictionary
ContentProvider
中的一组数据("table")。
is this uri to table file where sqlite stored?
这是 ContentProvider
的开发者决定的。 ContentProvider
API 没有规定数据存储在哪里。它可以存储在 SQLite 中,或 JSON 文件中,或其他任何地方。 约定 表示 ContentProvider
公开的数据集合映射到 SQLite table 或视图,但这不是必需的。
if it's, how do I know mine?
如果您使用 user_dictionary
作为权限,您就知道它是您的 ContentProvider
(请参阅清单中 <provider>
元素中的 android:authorities
)。
I mean where did my sqlite store table that I created?
这取决于你。 ContentProvider
与 SQLite 无关,除非 你 编写代码将 ContentProvider
实现与 SQLite 联系起来。
ContentProvider just like a repository
不是真的,至少在我如何使用术语 "repository" 方面是这样。 ContentProvider
是一些数据存储机制的包装器,允许外部各方控制对该数据的访问。
can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?
那会比较难。这也是很少有开发者使用 SyncAdapter
.