Previous State (entered/exited region) lost after stopping and starting again the monitoring

Hello,
I am working on a Android project, My scenario is like this: when user starts to Walk (given by step counter sensor), then I have to “Start Monitoring” to see if user enters or exits the beacon region, and after handling my event, I “Stop Monitoring” the region to save battery ( i.e., user stays in his room for one hour). If user starts to walk again (to exit the room), I start monitoring the regions again, BUT, when I “Start Monitoring” the same region (room) for the SECOND time, the previous state of the first monitoring is not preserved.( the Exit Region should be triggered by the second monitoring, but it never happens, when I am out of region)

1- User enters the region (Entered event happens), Then I Stop Monitoring
2- User stays in his room for 30 Minutes
3- User starts walking to Exit the region. --> Exit Region never happens<-- my problem!

Also, does Exit Event happens, if Enter event have not happened before?

Thank you for your suggestions.

Just to make sure I understand correctly, what happens is:

  1. You start monitoring.
  2. You go into the room, enter happens.
  3. You stop monitoring.
  4. You re-start monitoring.
  5. You go out of the room, no exit happens.
  6. You go back into the room, … does an enter happen?
1 Like

This is how it happens:

1- I start monitoring.
2- I go into the room, enter happens.
3- I stop monitoring.(i.e., for 30 minutes long)
4- I go out of the room (monitoring is still stopped)
5- I re-start monitoring.
6- no exit happens.<-- (this is my issue), why Exit Event is not happening?
7- I go back into the room, … does an enter happen? (yes, it happens, as it should be)

Thanks

Ah, thanks! If you’re not monitoring when the user is leaving the room, then yes, you won’t get the exit event, that’s by design. In your use case, this maybe would’ve made sense, but I can also think of a dozen more when that would be confusing.

You should still be able to handle this yourself though—just remember the last state in your own code. Then, when the user left the room, you can start ranging, see that the user is no longer in range of the beacon (and so, outside the room), compare that to the last state (“the user was inside the room 30 minutes ago”), and trigger an appropriate action.

Why do you stop monitoring BTW? Does it drain too much battery? What Android device and Android OS did you test with? Modern Android devices can do background Bluetooth scanning very efficiently, so it shouldn’t be a problem.

Thank you for the suggestions,
I am writing on Android Wear smartwatches, and the battery sources are limited, about 350 mAh to 450 mAh.
So, I try to stop monitoring when it is not necessary (user is not walking). And I re-start monitoring when user starts moving (I detect user movement by Step Counter Sensor), and then I stop monitoring after 2 minutes if no user movement detected by setting a timer.

Regarding the ranging, I would like all the process to be executed in background. Is it possible to do ranging in a Background Service?

Gotcha—keep in mind you can always tweak the scanning settings to further improve energy consumption. By default, we scan for 10 seconds every 30 seconds, but you could make it e.g., 10 seconds every minute, or two minutes:

https://github.com/Estimote/Android-SDK/blob/master/DOC_monitoring_scanning.md#5-set-scan-periods

As for ranging in the background—ranging already is performed in our own background service, so it should work in the background “out of the box”.