Android:在运行时切换内容提供者
你好
我的应用程序实现了 2 个内容提供程序:
1)本地-基于Sqlite
2) 远程 - 基于应用程序引擎。
当我与互联网断开连接时,我想使用#1。
当我有互联网连接时,我想切换到#2。
我怎样才能做到这一点?
谢谢
Avishay
[30 分钟后...:-)
经过更深入的研究,我认为通过切换“内容提供商 URI”我可以从 #1 切换到 #2。
阿维沙伊
Hi
My application implements 2 content providers:
1) Local - based on Sqlite
2) Remote - based on app engine.
When I am disconnected from the internet I want to use #1.
When I have internet connectivity I would like to switch to #2.
How can I do that?
Thanks
Avishay
[30 min later... :-)
After a deeper research I think that by switching the "content provider URI" I can switch from #1 to #2.
Avishay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但正确的答案是使用
ContentProvider
,并使用SyncAdapter
来保持ContentProvider
的数据库不断变化与 App Engine 数据库同步。这将为您提供快速的本地数据访问,并确保您始终使用一个一致的数据库。否则,您将拥有两组完全不同的数据,一组在连接时,另一组在未连接时不同。Google I/O 2010 上有一个关于此内容的精彩视频演示。请参阅:开发 Android REST 客户端应用程序
But the right answer is to use a
ContentProvider
, and use aSyncAdapter
to keep theContentProvider
's database constantly in sync with the App Engine database. This will provide you fast local data access, and ensure that you're always running out of one consistent database. Otherwise, you'll have two totally different sets of data, one when you're connected, and a different when not.There's a great video presentation about this that was presented at Google I/O 2010. See: Developing Android REST client applications