Region exit events

Hello, first of all I’m a noob on Android and estimote development, so probably this is going to be pretty easy to answer for you.

I have been working with estimote android examples, I have a notification activity and I have been trying to modify some functionality in order to get familiar with the technology, this notification activity is going to display the notification at the top of the screen and also will display another activity that I have created, it basically has an image view, as soon as the devices leaves the region the device should display another notification, telling the user that it has left the region and also get back to the previous activity.

Currently my app is capable to displays the image view and notification as soon as the device enters the regions, also it displays the notification when it leaves the region, however I’m not capable to return to the previous activity as soon as it leaves the region, this is my code:

beaconManager.setMonitoringListener(new MonitoringListener() {
  @Override
  public void onEnteredRegion(Region region, List<Beacon> beacons) {

      Intent intent = new Intent(NotifyDemoActivity.this, ImageActivity.class);
      postNotification("Entered region");
  }

  @Override
  public void onExitedRegion(Region region) {

      postNotification("Exited region");
      finish();
  }
});

Thanks in advance

Hey hello, welcome to the community! :smile:

You mentioned that you get a notification when you leave the region, suggesting that the onExitedRegion method is being called just fine—which means something could be wrong with your finish method. Want to share some of its code?

In this case I didn’t overloaded The finish method, so it is The default android implementación.

Hi axcha15,

Monitoring events are not delivered on main thread so your finish() will not work correctly. Do:

runOnUiThread(new Runnable() { public void run() { finish(; )} });

Instead of calling directly finish() can you do following:
1/ stop monitoring: beaconManager.stopMonitoring(...)
2/ disconnect from manager: beaconManager.disconnect()
3/ call finish()