微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android远程进程:messenger vs aidl?哪个更好?

我目前有一个远程服务,可以与同一个应用程序上的活动进行持续通信.

我需要在某些时候广泛地发送和发送消息.哪种消息传递方式更好,更快,更适合电池使用?使用消息或aidl接口?

截至目前我正在使用aidl接口,但由于某种原因,我认为在附加监听器时会有很多开销……

任何反馈都非常感谢.

解决方法:

I currently have a remote service that communicates constantly with an activity on the same app.

远程服务通常不是一个好主意.

Well, my app is a multimedia audio application that needs to run in the background which requires a lot of resources: memory. Having this in the same process as my activities would most likely bring issues to reaching the limit of resource usage per process.

然后使用更少的内存.即使有活动,音频播放器也不需要超过每进程RAM限制.

Also, the benefits are, if your UI crashes for some reason your service doesn’t.

这不是浪费设备RAM和cpu间的特别好的理由.对于服务器来说,这是一种很好的方法,对于嵌入式系统来说则更是如此.

Which method of messaging is better, faster, and battery friendly? Using messages or aidl interface?

它们应该具有可比性. IPC考虑应该淹没大多数其他影响.例如,从我的一本书中引用自己:

For example, in the cpu-Java/AIDloverhead directory of the book’s source
code, you will find a pair of projects implementing the same do-nothing
method in equivalent services. One uses AIDL and is bound to remotely
from a separate client application; the other is a local service in the client
application itself. The client then calls the do-nothing method 1 million
times for each of the two services. On average, on a Samsung galaxy Tab
10.1, 1 million calls takes around 170 seconds for the remote service, while it
takes around 170 milliseconds for the local service. Hence, the overhead of
an individual remote method invocation is small (~170 microseconds), but
doing lots of them in a loop, or as the user flings a ListView, might become
noticeable.

话虽这么说,如果你担心开销(但坚持远程服务),你可能更好地尝试两者并使用日志来确定是否有明显的赢家.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐