哪个性能密集度较低 - 通过 Intent 传递包或使用 Content Provider

发布于 2024-09-26 09:23:03 字数 343 浏览 3 评论 0原文

我想在 Android 中的两个应用程序之间传递大量数据(~1500 字节),其中性能和资源分配是优先考虑的。数据基本上是键值对。它需要从一个应用程序传递到另一个应用程序的速率可能会有所不同,从一秒钟内的一小滴到大约 50 个数据包。我想我可以:

  1. 将所有数据包装在一个包中,并通过 Intent 将包从一个应用程序传递到另一个应用程序。我担心分配和取消分配所有内存来存储包的性能影响。

  2. 将所有数据写入 SQLite 数据库,并通过内容提供程序将其提供给其他应用程序。在这里,我担心将所有数据写入磁盘,然后在请求时必须从磁盘读回的性能影响。

那么,两害相权取其轻呢?

I would like to pass a considerable sized amount of data (~1500 bytes) between two applications in Android where performance and resource allocation is a priority. The data is basically key-value pairs. The rate at which it needs to be passed from one application to another can vary from a trickle to ~50 packets within a second. I figure I can either:

  1. Wrap all the data inside a bundle, and pass the bundle via an Intent from one application to another. I worry about the performance implications of allocating and de-allocating all that memory to store the bundles.

  2. Write all the data to a SQLite database and provide it to the other application via a content provider. Here I worry about the performance implications of writing all that data to disk, and then having to read it back from disk when it is requested.

So, which is the lesser of two evils?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2024-10-03 09:23:03

考虑使用服务连接。您在设置初始连接时付出了一些开销,但之后,您可以使用类似 RPC 的接口以很少的开销(远低于毫秒)进行方法调用(在任一方向传递 Parcelable 结构)。有关详细信息,请参阅此页面

Consider using a service connection. You pay some overhead in setting up the initial connection, but after that, you can use an RPC-like interface to make method calls (passing Parcelable structures in either direction) with very little overhead (well under a millisecond). See this page for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文