-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for running service in a separate process #479
Conversation
The |
Here is a description of how this PR affects library settings when the BeaconService is configured to run in its own process. This change does not affect settings when running in the same process. Settings respected:The following settings may be changed the same way regardless of whether the BeaconService
Settings requiring modifications:The following settings will only be applied if
Settings ignoredThe following settings are ignored when made from the main process and the BeaconScanner
|
@davidgyoung As you said |
@paulbao, if you have a two process setup, you can freely access the range/monitor notifiers from your main app process that does not host the beacon scanning service. You simply cannot access and modify them from the process that does host the scanning service. This is because the library relies on a singleton manager to hold these notifiers (one singleton instance exists per process) and it is not kept in sync across processes. |
Thanks for quick reply @davidgyoung , I'm a little bit confused that range/monitor notifiers are interface, shouldn't I implemented them somewhere(Used to be |
On Oct 10, 2017 11:03 AM, "paulbao" <notifications@github.com> wrote:
Thanks for quick reply @davidgyoung <https://github.com/davidgyoung> , I'm
a little bit confused that range/monitor notifiers are interface, shouldn't
I implemented them somewhere(Used to be BeaconManager.addRangeNotifer())
then I can got the callback.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#479 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_xcSRHGt6Bq7bAxOMFvyTsZEHO6Wi6ks5sqt59gaJpZM4MaCY0>
.
You generally do not need to worry about this and it all just works. If,
however, you are executing code where you don't know which process it is
running in and setting up range /monitor notifiers, just wrap the code like
this:
If (beaconManager.isMainProcess()) {
// Configure your app to start ranging and monitoring here
beaconManager.addMonitorNotifier(...);
beaconManager.startMonitoringRegion(...);
}
You define your classes that implement the notifier interfaces normally.
The only change for a multi process setup is that you only start the beacon
scanning in the main process as shown above.
|
This fixes a minor issue where the running average is not set after restoring a beacon from a parcel. Looking at the history it seems that the running average was an internal detail until #479 where support was added for running the service in a separate process. Part of the reason this needs to be included is that on Android 8.0 the running average _is_ restored and available for access. The reason the behavior is different across Android versions is in the way a service intent versus local notification handles the data `Bundle` (i.e. which [`Callback`](https://github.com/AltBeacon/android-beacon-library/blob/2.12.3/src/main/java/org/altbeacon/beacon/service/Callback.java#L58-L86) branch runs). Explicitly setting the `BeaconManager` to use scheduled scan jobs, forcing the first conditional code path using local notifications, allows the running average to be available on older versions.
This fixes a minor issue where the running average is not set after restoring a beacon from a parcel. Looking at the history it seems that the running average was an internal detail until #479 where support was added for running the service in a separate process. Part of the reason this needs to be included is that on Android 8.0 the running average _is_ restored and available for access. The reason the behavior is different across Android versions is in the way a service intent versus local notification handles the data `Bundle` (i.e. which [`Callback`](https://github.com/AltBeacon/android-beacon-library/blob/2.12.3/src/main/java/org/altbeacon/beacon/service/Callback.java#L58-L86) branch runs). Explicitly setting the `BeaconManager` to use scheduled scan jobs, forcing the first conditional code path using local notifications, allows the running average to be available on older versions.
@davidgyoung |
@kanagalraj, this is the first report I have heard of library threads (which are used to parse beacon packets when they arrive) impacting other functions. I suspect the issue you are experiencing may have a different root cause than you expect. Either way, please post a question on StackOverflow.com showing your setup code and any logs or other evidence showing the symptoms you are seeing. Glad to take a look there. |
@davidgyoung |
@davidgyoung I'm trying to use the library (v 2.16.1) in a separate process - I'm starting it from the service running separate process. There is no code regarding beacons running in main process. Trying to setup ranging notifier I'm getting no reading nor exceptions / errors. When I remove Any help? :) Thanks |
This adds support for running the beacon scanning service in a separate process and working with application setups that have more than one process. This is needed in two cases:
This addresses the problems described in #306
The change includes:
In order to test this with an app you can force the BeaconService to run in a separate process by adding this entry to your application's manifest:
If configuring beacon scanning using a custom
Application
class, thisApplication
class will get started once for each process. You will only want to perform the setup activities once, typically in the main process that hosts the UI. You can do this using thebeaconManager.isMainProcess()
helper as shown: