Android beacon library oscillates between on and off with a fast pace

Android beacon library oscillates between on and off with a fast pace



I used the android beacon library to do the following action:

I switched on and off with a fast pace. On and off, on and off, and so on for 8-9 times.

However, the beacon then lost the signal for about 10 seconds and then the signal started to be received again.

Also, I tried an Android API function, "lescan", which resulted in the same situation.



Does anyone know why this happens?



MY testing device is:



Samsung S6 7.0



override fun onResume()
beaconManager = BeaconManager.getInstanceForApplication(this)
beaconManager.getBeaconParsers().add(BeaconParser().
setBeaconLayout(IBEACON_LAYOUT))
beaconManager.getBeaconParsers().add(BeaconParser().
setBeaconLayout(EDDYSTONE_UID_LAYOUT))
beaconManager.getBeaconParsers().add(BeaconParser().
setBeaconLayout(EDDYSTONE_URL_LAYOUT))
beaconManager.getBeaconParsers().add(BeaconParser().
setBeaconLayout(EDDYSTONE_TLM_LAYOUT))
beaconManager.bind(this)


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
val permissions = ArrayList<String>()
if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION)
if (permissions.size != 0)
ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 100)





override fun onBeaconServiceConnect()
beaconManager.addRangeNotifier beacons,region ->
Log.d("addRangeNotifier",beacons.size.toString())

try
beaconManager.startRangingBeaconsInRegion(Region("com.gigabyte.testkotlin", null, null, null))
catch (e: RemoteException)
e.printStackTrace()


override fun onPause()
super.onPause()
beaconManager.unbind(this)





When you say "switched on and off", do you mean you turn bluetooth on and off or you turn scanning on and off? How long a period do you do this -- 8 or 9 times per second or over a longer period like 60 seconds?
– davidgyoung
Sep 2 at 17:05






I turned scanning on and off for 8-9 times in a fast pace, approximately in 10 seconds.
– Jerry Lin
Sep 4 at 1:30




1 Answer
1



It's hard to say exactly what you are witnessing without seeing exact code to reproduce, but turning scanning on and off quickly is not necessarily a problem on all devices.



By default, the Android Beacon Library uses a foreground scan period of 1100 ms and a between scan period of 0ms, so it effectively turns scanning on and off 9 times in just over 10 seconds -- similar to what you describe.



I have never noticed these symptoms in normal use of the library on Samsung devices or the Huawei P9, so something else must be triggering this behaviour in your test case.



EDIT: The posted code indicates that the activity itself is what is started and stopped rapidly, and because it binds and unbinds to the beaconManager as it starts and stops, it also starts and stops the Android service that scans for beacons. These are heavy weight data structures that are not designed to be started and stopped rapidly. Short answer: don't do this. If you really need to start and stop your activity rapidly, bind to the beaconManager outside the activity lifcycle, perhaps only one at app startup in the onCreate method of a custom Android Application class.





This's part of my Activity,try to quick Resume Pause keep 8-9 times then you will fine out
– Jerry Lin
Sep 5 at 9:05






Ok,if I do that like you said in Application onCreate what lifcycle should stop if don't stop it will power consumption, I tried this before
– Jerry Lin
Sep 6 at 1:32





You can use BackgroundPowerSaver, which will scale back scans when all activities are in the background. If you really don't want background scans at all, just set beaconManager.setBackgroundBetweeenScanPeriod(999999999), or some other very large number so they effectively never happen.
– davidgyoung
Sep 6 at 11:26


beaconManager.setBackgroundBetweeenScanPeriod(999999999)



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?