您想在您的Android应用程序中集成基于POJO或Cursor的库吗? [英] Would you like to integrate a POJO- or Cursor-based library in your android app?

查看:97
本文介绍了您想在您的Android应用程序中集成基于POJO或Cursor的库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司想发布一个Android的库,以便其他人可以轻松地将我们的内容集成到其自定义应用程序中.

My company wants to publish a library for android, so that other people can integrate our content easily in their custom apps.

现在,我仍然不确定如何提供内容.现在,我正在使用POJO在项目中提供数据.

Now I am still very uncertain how I should provide the content. Right now I am using POJOs to provide the data in my project.

我正在跟踪辩论"POJO与游标" ,结果游标的青睐.我还看过示例,其中有人将解析后的资源存储在SQLLite-DB中,并在以后通过游标对其进行访问.

I was following the debate "POJOs vs. Cursors" which turned out in favor of Cursors. I also have seen an example where somebody stores the parsed resource in a SQLLite-DB and accesses it later through Cursors.

我知道,与POJO相比,游标具有许多优势.但是,当您需要实现一个库时,您是否想弄乱游标?你们中有些人可能也写过此类库.您使用了什么,为什么?

I know that Cursors have many advantages compared to POJOs. But would you like to mess with cursors when you need to implement a library? Some of you guys might have written such libs as well. What did you use and why?

其他库的运行方式...

Facebook似乎使用POJO:

响应格式:服务器响应是JSON字符串. SDK提供了一个Util.parseJson()方法,可将其转换为JSONObject,可以检查和访问其字段和值.

Response format: The server response is a JSON string. The SDK provides a Util.parseJson() method to convert this to a JSONObject, whose fields and values can be inspected and accessed.

推荐答案

我们在上一个项目中使用了Cursor方法,发现它很麻烦.特别是必须检查游标中是否确实存在某些东西,对其进行迭代,为值找到正确的索引,正确地将其关闭..这不是我喜欢一遍又一遍地做的事情.特别是整个索引的东西往往很容易折断,特别是因为如果您实际上在使用投影,则无法为其定义常量.

We used the Cursor approach in our last project, and found it quite cumbersome. Especially having to check whether there's actually something in the Cursor, iterating over it, finding the right indices for values, closing it properly.. not something I like to do over and over again. Especially the whole index stuff tends to break quite easily, especially since you can't define constants for it if you're actually making use of projections.

一个好的方法可能是使用Cursor支持的POJO,至少在集合方面.这样,可以按需读取数据.不过,您仍然必须找到一种明智的方式来关闭光标.

A good approach would probably be to use Cursor backed POJOs, at least when it comes to collections. That way the data could be read on demand. You still would have to find a sensible way to close the cursor then, though.

如果是单个对象,我会用投影对地狱说,然后将其所有内容都转储到POJO中.

In case of single objects, I say to hell with projections and just dump everything it into a POJO.

这篇关于您想在您的Android应用程序中集成基于POJO或Cursor的库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆