Notification pops up too often - Android

I downloaded the Notification demo for Android with Java. My phone is running Android 9.0. I have two problems.

  1. It gives onEnter and onExit notifications randomly.
  2. It does work when enter or exit the region of the beacon, however it displays the time with the previous notifications. For example, if I exited and entered the region at 7:00 pm, when I exit at 7:30 pm it gives a good by notification with 7:00 pm. It works same when I enter, it seems that it displays previous notification time.

Does anyone have similar issues or know the solution?