Reputation: 3290
I've developed a foreground service which should handle a Bluetooth Low Energy communication between a specific HW device.
This service has got an activity in which you can set up some parameters to manage the service, anyway it works with the activiy killed too.
The service contains a BootReceiver too and it is started with the device boot.
Now, my aim is to create another projects with one or more activityes, those one have to communicate with the service and excange data.
I've looked for an aswer on the net and those are the results:
It seems like this one is the correct one but it is a lot complicated and it involves a lot of code for a little data.
Broadcast receiver is easy to implement, but what if i should read some data from bluetooth each 100ms for example? I don't think this is the correct way.
Which is the correct way of implementing a communication like that?
Upvotes: 0
Views: 292
Reputation: 106
In android we have several ways to share data between application, it's depend on - how many data do you want to share between applications, cyber issues, Battery consumption and timing issues:
1) You can use aidl in both app in order to share data, please be aware that you are not able to send objects, you should convert the data to parcelable or byte-array. pros - great solutions for short data.
2)SharedPreferences and use the same android:sharedUserId="android.uid.share" on both application - not recommended due a battery consumption and timing issue, great to share big data.
3)You can use client/server model and open a unix socket on bot applications - pros - reliable and can be secured, cons - short battery life.
4)Broadcast receiver - [not recommended] due a potentially timing issue.
5)using shared file at sdcard - not recommended.
Upvotes: 1