Open VolodaUa opened 1 month ago
HI @davidgyoung
Could you please take a look?
We used this library when we had one Activity only(Xamarin) and we didn't observe this issue. We also started using it in the project where we have a couple of activities(native) and we got that app scans too frequently messages in the log cat. I started an investigation and I found that it looks like the app restarts scanning every time when we have navigation. I attached the sample when it reproduces. The sample was built according to documentation when an application is used to create the instance of BeaconManager.
Hi @davidgyoung
I found that BackgroundPowerSaverInternal works wrongly in the sample app.
It always considers navigation like the user puts the app in the background.
Expected behavior
The scan job should not restart every time once you have next/back navigation
Actual behavior
The scan job restarts scanning every time when another activity is opened. As a result, the app gets the error: "App 'com.example.myapplication' is scanning too frequently" in the log cat and scanning doesn't work for some time.
class MyApplication : Application(), MonitorNotifier { override fun onCreate() { super.onCreate() val beaconManager = BeaconManager.getInstanceForApplication(this) beaconManager.addMonitorNotifier(this) beaconManager.startMonitoring(region) } ... }
From documentation:
There are subtle changes with the initial background state when using autobind. If you use autobind methods to start ranging or monitoring from Application.onCreate or any method in its call stack, then the library will **start scanning in background mode**. If you initiate scanning at any other time (from a custom service or from an activity or fragment) then the library will start out in foreground mode provided that the screen is on. Previously, the library always started out in foreground mode unless using RegionBootstrap, in which case it started out in background mode.
As I understood correctly, it should perform background scanning if I have starting of monitoring beacons in the Application.onCreate method. and should not restart scanning every time on navigation. Looks like it doen't work.
Steps to reproduce this behavior
1) Launch the sample app 2) Close the app, go to settings and grant all the permissions; 3) Open the app again; 3) See the Job started scanning 4) See logs Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@a1bb557 scanJob version 2.20.2 is starting up on the main process 5) Open next activity by button;
Mobile device model and OS version
Google Pixel 7 Pro, Android 14
Android Beacon Library version 2.20.6
Sample: BeaconsApplication.zip
IMPORTANT: This forum is reserved for feature requests or reproducible bugs with the library itself. If you need help with using the library with your project, please open a new question on StackOverflow.com.