简体   繁体   中英

Need some guidance with multi-app IPC

All I'm really looking for here is a little guidance. I'm trying to create my first official android app. I'm new to java/droid but not programming. Over the past month I've created quite a number of little experimental activities, services, threads and whatnot and they all function as planned. So now I'm trying to tie is all together but not having much luck.

In a new project I've compiled the guts into 'my.main.package' which runs a service that is constantly crunching data that other clients/apps can use… Well that's my plan. For example, in this service is a custom thread/loop timer that is constantly counting. What would be the best way for any other apps to get a constant feed of this timer and other data as a listener could within its own sandbox and in the least taxing way possible?

I'm assuming one must implement aidl for IPC but I'm not sure if its needed and/or necessary as data from my.main.package is only outgoing, ie other apps only need receive/listen. I understand there needs to be some form of message handling or parcelable marshalling going on and possible permissions with aidl but I got to thinking that encoding/decoding a parcel or sending a message every millisecond would be very taxing. Is aidl the only way to go or is there a way to broadcast data as you can intent?

Any help would be greatly appreciated!

In fact, IPC with AIDL is the only & the most effective way to do your requirements, I think. If you need one demo, you can take a look here . It's a simple example I wrote to learn AIDL & Binder on Android. Hope it could give you some brief for starting.

In a new project I've compiled the guts into 'my.main.package' which runs a service that is constantly crunching data that other clients/apps can use

A service should only be running when it is actively delivering value to the user . Users think that developers who create services that run all of the time are idiots and attack their apps with task killers, force-stops from the Settings app, etc.

Perhaps your description is just depicting your app in a poor light, but "a service that is constantly crunching data" is an anti-pattern. These are phones and tablets, not servers.

What would be the best way for any other apps to get a constant feed of this timer and other data as a listener could within its own sandbox and in the least taxing way possible?

The best way is for them not to be separate apps in the first place.

For example, in this service is a custom thread/loop timer that is constantly counting.

This is not adding value to the user.

I'm assuming one must implement aidl for IPC but I'm not sure if its needed and/or necessary as data from my.main.package is only outgoing, ie other apps only need receive/listen.

A remote service using AIDL is one way of doing IPC. It is not the only way. It is not even the most common way. You can also:

  • send a broadcast Intent
  • have the client send a Messenger to the service, and the service sends messages to the client via that Messenger
  • have the service update a ContentProvider , and have clients register a ContentObserver on the ContentProvider

I understand there needs to be some form of message handling or parcelable marshalling going on and possible permissions with aidl but I got to thinking that encoding/decoding a parcel or sending a message every millisecond would be very taxing.

IPC is "very taxing" in general. Hence, IPC should be avoided wherever possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM