重新启动Android应用后,didRangeBeaconsInRegion()多次调用 [英] didRangeBeaconsInRegion() call multiple times after restarts Android app
问题描述
我正在开发可在信标附近扫描的Android应用。
第一次打开Android应用程序并扫描信标,并且每2秒调用一次didRangeBeaconsInRegion()方法。
I am developing Android app which scan near Beacons. Very first time open Android app and scan near beacons and didRangeBeaconsInRegion() method call every 2 seconds.
但是当我关闭应用程序后再次启动然后didRangeBeaconsInRegion( )方法在2秒内调用了2次
But when I close app then again starts then didRangeBeaconsInRegion() method called 2 times in 2 seconds
第三次didRangeBeaconsInRegion()方法在2秒内调用了3次
3rd time didRangeBeaconsInRegion() method called 3 times in 2 seconds
等等...
代码段
@Override
public void didRangeBeaconsInRegion(final Collection<Beacon> beacons, final Region region) {
if (beacons != null) {
Log.i("iBeacons", "beacons.size() : " + beacons.size());
}
}
日志:
2018-12-29 21:39:40.328 26528-27120/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:40.328 26528-27120/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:40.328 26528-27120/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:42.259 26528-27124/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:42.260 26528-27124/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:42.260 26528-27124/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:44.229 26528-27132/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:44.229 26528-27132/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:44.229 26528-27132/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:46.241 26528-27136/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:46.241 26528-27136/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:46.241 26528-27136/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:48.251 26528-27138/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:48.251 26528-27138/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:48.251 26528-27138/com.test.demo I/iBeacons: beacons.size() : 1
2018-12-29 21:39:50.249 26528-27139/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:50.249 26528-27139/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:50.249 26528-27139/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:52.241 26528-27141/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:52.241 26528-27141/com.test.demo I/iBeacons: beacons.size() : 0
2018-12-29 21:39:52.241 26528-27141/com.test.demo I/iBeacons: beacons.size() : 0
< hr>
更新2:
Update 2:
此处是回调代码
mBeaconManager.addRangeNotifier(this);
一旦用户允许信标扫描操作获得所有必要的许可,上述回调仅被调用一次表单应用程序
Above callback is called only one time form application once user allow all necessary permission for beacon scan operation
问题:第一次运行正常,但是第二次,第三次出现问题,...重新启动。
我是在第三次重新启动应用程序时在日志上方捕获的。
Problem: It is working fine in first time but issue with 2nd time, 3rd time, ... restarts. I captured above logs when application was restarts 3rd time.
注意:当我清除应用程序表单时,它也可以正常工作
Note: It is also working fine when I clear the application form background.
推荐答案
mBeaconManager.removeRangeNotifier(this);
这篇关于重新启动Android应用后,didRangeBeaconsInRegion()多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!