ANR on phone boot and LocationServiceImpl not calling startForeground()
See original GitHub issueYour Environment
- Plugin version: 0.6.3
- Platform: Android
- OS version: Android 8
- Device manufacturer and model: Samsung S7
- Running in Simulator: No
- React Native version: 0.61.4
- Plugin configuration options:
{
desiredAccuracy: BackgroundGeolocation.PASSIVE_ACCURACY,
stationaryRadius: 500,
distanceFilter: 100,
notificationsEnabled: true,
debug: true,
startForeground: true,
startOnBoot: true,
stopOnTerminate: false,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 15000,
fastestInterval: 5000,
activitiesInterval: 10000,
}
- Link to your project: private
Context
Expected Behavior
Expected service to be running as foreground service after phone reboot
Actual Behavior
Crashes with ANR
Possible Fix
Steps to Reproduce
- Configure new project
- Reboot device
- Watch logcat
- See the ANR
Context
No reporting after reboot
Debug logs
2019-12-06 17:12:26.603 10869-10869/app.nakre.debug D/com.marianhello.bgloc.BootCompletedReceiver: Received boot completed
2019-12-06 17:12:26.613 10869-10919/app.nakre.debug I/FA: App measurement is starting up, version: 18079
2019-12-06 17:12:26.613 10869-10919/app.nakre.debug I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2019-12-06 17:12:26.614 10869-10919/app.nakre.debug I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app app.nakre.debug
2019-12-06 17:12:26.653 10869-10869/app.nakre.debug D/com.marianhello.bgloc.BootCompletedReceiver: Boot completed Config[distanceFilter=100 stationaryRadius=500.0 desiredAccuracy=10000 interval=15000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=true startOnBoot=true startForeground=true notificationsEnabled=true locationProvider=1 nTitle=Nakre nText=Yük arama... nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate=null]
2019-12-06 17:12:26.653 10869-10869/app.nakre.debug I/com.marianhello.bgloc.BootCompletedReceiver: Starting service after boot
2019-12-06 17:12:26.850 10869-10877/app.nakre.debug I/zygote64: Do partial code cache collection, code=29KB, data=19KB
2019-12-06 17:12:26.850 10869-10877/app.nakre.debug I/zygote64: After code cache collection, code=29KB, data=19KB
2019-12-06 17:12:26.850 10869-10877/app.nakre.debug I/zygote64: Increasing code cache capacity to 128KB
2019-12-06 17:12:26.902 10869-10869/app.nakre.debug I/com.marianhello.bgloc.service.LocationServiceImpl: Creating LocationServiceImpl
2019-12-06 17:12:26.912 3664-8109/? W/AccountManagerService: insertAccountIntoDatabase: Account {name=Locations, type=app.nakre.debug.mauron85.bgloc.account}, skipping since the account already exists
2019-12-06 17:12:26.915 10869-10869/app.nakre.debug I/com.marianhello.bgloc.PostLocationTask: Creating PostLocationTask
2019-12-06 17:12:26.920 10869-10946/app.nakre.debug I/com.marianhello.bgloc.service.LocationServiceImpl: Network condition changed has connectivity: true
2019-12-06 17:12:26.926 10869-10869/app.nakre.debug D/com.marianhello.bgloc.service.LocationServiceImpl: Service in [NOT STARTED] state. cmdId: [N/A]. startId: [1]
2019-12-06 17:12:31.686 3664-3684/? W/ActivityManager: Bringing down service while still waiting for start foreground: ServiceRecord{dac9568 u0 app.nakre.debug/com.marianhello.bgloc.service.LocationServiceImpl}
2019-12-06 17:12:31.689 10869-10869/app.nakre.debug I/com.marianhello.bgloc.service.LocationServiceImpl: Destroying LocationServiceImpl
2019-12-06 17:12:31.769 10869-10878/app.nakre.debug I/zygote64: Thread[3,tid=10878,WaitingInMainSignalCatcherLoop,Thread*=0x76502c1400,peer=0x12d80750,"Signal Catcher"]: reacting to signal 3
2019-12-06 17:12:32.039 10869-10878/app.nakre.debug I/zygote64: Wrote stack traces to '/data/anr/traces.txt'
2019-12-06 17:12:32.041 3664-3684/? E/ActivityManager: ANR in app.nakre.debug
PID: 10869
Reason: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dac9568 u0 app.nakre.debug/com.marianhello.bgloc.service.LocationServiceImpl}
Load: 0.0 / 0.0 / 0.0
CPU usage from 69340ms to 0ms ago (2019-12-06 17:11:21.673 to 2019-12-06 17:12:31.687):
68% 3664/system_server: 46% user + 22% kernel / faults: 134711 minor 1802 major
11% 4274/com.google.android.gms.persistent: 7.8% user + 3.8% kernel / faults: 37040 minor 732 major
10% 5737/com.touchtype.swiftkey: 9.5% user + 0.5% kernel / faults: 50150 minor 32 major
8.1% 894/kswapd0: 0% user + 8.1% kernel
7.6% 5274/com.google.android.gms: 5.3% user + 2.2% kernel / faults: 27392 minor 159 major
6.9% 3103/logd: 2.8% user + 4% kernel / faults: 2704 minor 12 major
4.4% 4933/com.google.android.googlequicksearchbox:interactor: 3.4% user + 1% kernel / faults: 3631 minor 1334 major
4% 3301/zygote64: 0.6% user + 3.4% kernel / faults: 24364 minor
3.6% 1628/mc_fastcall: 0% user + 3.6% kernel
3.6% 3208/surfaceflinger: 0.9% user + 2.6% kernel / faults: 1770 minor 150 major
3.3% 3104/servicemanager: 1.1% user + 2.1% kernel / faults: 245 minor 1 major
3.2% 4829/com.google.process.gapps: 1.7% user + 1.4% kernel / faults: 5547 minor 3 major
2.9% 4975/com.google.android.googlequicksearchbox:search: 2.1% user + 0.7% kernel / faults: 15185 minor 661 major
2.8% 3190/android.hardware.audio@2.0-service: 0.7% user + 2.1% kernel / faults: 385 minor 33 major
2.6% 6010/com.samsung.android.app.cocktailbarservice: 2.1% user + 0.5% kernel / faults: 29887 minor 58 major
2.4% 4081/com.android.systemui: 1.3% user + 1% kernel / faults: 14574 minor 608 major
2.2% 4394/com.android.phone: 1.4% user + 0.8% kernel / faults: 8749 minor 445 major
1.6% 5050/com.sec.android.app.launcher: 1.2% user + 0.4% kernel / faults: 13583 minor 89 major
1.4% 3306/audioserver: 0.7% user + 0.6% kernel / faults: 854 minor 12 major
1.1% 3307/cameraserver: 0.4% user + 0.6% kernel / faults: 8666 minor 43 major
0.9% 3278/jbd2/dm-1-8: 0% user + 0.9% kernel
0.8% 656/spi1: 0% user + 0.8% kernel
0.8% 860/cfinteractive: 0% user + 0.8% kernel
0.8% 3207/lmkd: 0.1% user + 0.6% kernel / faults: 58 minor
0.7% 1996/kworker/u17:1: 0% user + 0.7% kernel
0.6% 5310/android.process.acore: 0.4% user + 0.2% kernel / faults: 5151 minor 1 major
0.6% 3085/kworker/u17:2: 0% user + 0.6% kernel
0.6% 4723/kworker/3:2: 0% user + 0.6% kernel
0.6% 10/migration/0: 0% user + 0.6% kernel
0.4% 1978/kworker/0:1H: 0% user + 0.4% kernel
0.5% 13/migration/1: 0% user + 0.5% kernel
0.5% 3302/zygote: 0% user + 0.4% kernel / faults: 3567 minor 1 major
0.4% 866/kworker/4:1: 0% user + 0.4% kernel
0.4% 3087/kworker/u17:4: 0% user + 0.4% kernel
0.3% 3319/netd: 0.1% user + 0.2% kernel / faults: 1594 minor 20 major
0.3% 4048/com.android.bluetooth: 0.1% user + 0.2% kernel / faults: 2002 minor 7 major
0.3% 77/kworker/u17:0: 0% user + 0.3% kernel
0.3% 1306/kworker/u16:3: 0% user + 0.3% kernel
0.3% 3300/gpsd: 0.2% user + 0.1% kernel / faults: 858 minor 16 major
0.3% 4062/com.sec.android.inputmethod: 0.3% user + 0% kernel / faults: 1996 minor 20 major
0.3% 5162/com.samsung.android.service.peoplestripe: 0.2% user + 0.1% kernel / faults: 1985 minor 30 major
0.3% 662/kworker/5:1: 0% user + 0.3% kernel
0.3% 3322/wificond: 0% user + 0.2% kernel / faults: 207 minor 1 major
0.2% 1866/exynos_hp: 0% user + 0.2% kernel
0.3% 7/rcu_preempt: 0% user + 0.3% kernel
0.2% 5482/com.samsung.android.contacts: 0.1% user + 0.1% kernel / faults: 965 minor 1 major
0.2% 3299/lhd: 0.1% user + 0.1% kernel / faults: 180 minor
0.2% 8/rcu_sched: 0% user + 0.2% kernel
0.2% 1309/kworker/u16:4: 0% user + 0.2% kernel
0.2% 34/ksoftirqd/5: 0% user + 0.2% kernel
0.2% 3198/android.hardware.sensors@1.0-service: 0% user + 0.1% kernel / faults: 440 minor 15 major
0.2% 1818/s3c-fb-vsync: 0% user + 0.2% kernel
0.2% 5093/com.samsung.android.SettingsReceiver: 0.1% user + 0.1% kernel / faults: 2957 minor 81 maj
2019-12-06 17:12:32.042 3664-3684/? W/ActivityManager: anr : app.nakre.debug,0
2019-12-06 17:12:32.045 3664-3684/? I/ActivityManager: Killing 10869:app.nakre.debug/u0a396 (adj 902): bg anr
2019-12-06 17:12:32.051 3664-4125/? W/ActivityManager: Missing app error report, app = app.nakre.debug crashing = false notResponding = true
20
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Context.startForegroundService() did not then call Service ...
Solution: Call startForeground() in onCreate() for the Service which you ... without checking if framework had tried to start the service.
Read more >Context.startForegroundService() Did Not Then Call Service ...
The reason for this crash is “From Android 9 Pie if your service does not call startForeground within 5 seconds after it has…...
Read more >mauron85/react-native-background-geolocation (Raised $0.00)
No variants found for ':mauron85_react-native-background-geolocation'. ... ANR on phone boot and LocationServiceImpl not calling startForeground().
Read more >Context.startForegroundService() did not then call Service ...
When I start the service on 8.0 I see *BOTH* of the above messages in the log but then 5 seconds later, I...
Read more >Pitfalls of a foreground Service lifecycle - ProAndroidDev
startForegroundService() did not then call Service.startForeground(). If the ANR interval passed and the app is in the foreground, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mauron85 Guess I found the solution in the common library.
LocationServiceImpl.java
at line 272 onStartCommand method receives intent which is not null. However, intent has no extra to start the service. So as exception above saysReason: Context.startForegroundService() did not then call Service.startForeground()
there is no command to call start(), because is the start method is called in two conditions: when intent is null or it has an extra with command in it.Changing the line like below and rebooting the phone I could confirm the service started and notification appeared without human interference
Could send a PR but the common lib is inaccessible.
How about headless task? is it still working when user clear all from recently?