react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

App crash when using BackgroundGeolocation.stop()

Open hackyxicor opened this issue 7 years ago • 21 comments

Your Environment

  • Plugin version: 0.5.0-alpha.50
  • Platform: Android
  • OS version: any
  • Device manufacturer and model: any
  • Running in Simulator: yes
  • React Native version: 0.52.0
  • Plugin configuration options:
  • Link to your project: yes

Context

On calling

BackgroundGeolocation.stop()

app got freezed then crash after sometime

Expected Behavior

BackgroundGeolocation service should stop without any side effects

Actual Behavior

App got freezed then crash after sometime

Possible Fix

Steps to Reproduce

On calling

BackgroundGeolocation.stop()

Context

Unable to stop background geolocation service

Debug logs

2018-12-19 17:16:24.167 1641-1654/? E/ActivityManager: ANR in drivezy.admin PID: 23144 Reason: executing service drivezy.admin/com.marianhello.bgloc.service.LocationServiceImpl Load: 1.7 / 1.43 / 0.99 CPU usage from 26372ms to 0ms ago (2018-12-19 17:15:56.983 to 2018-12-19 17:16:23.355): 10% 23144/drivezy.admin: 8.4% user + 2.4% kernel / faults: 4304 minor 5.1% 1299/surfaceflinger: 0.4% user + 4.6% kernel / faults: 1 minor 4.2% 1641/system_server: 2.2% user + 1.9% kernel / faults: 4819 minor 1.4% 1343/audioserver: 0.1% user + 1.2% kernel 1% 1972/com.google.android.gms.persistent: 0.8% user + 0.2% kernel / faults: 132 minor 0.6% 1935/adbd: 0.1% user + 0.5% kernel / faults: 1145 minor 0.4% 1715/com.android.systemui: 0.2% user + 0.2% kernel / faults: 3 minor 0.3% 22405/kworker/u5:2: 0% user + 0.3% kernel 0.2% 21036/kworker/u5:0: 0% user + 0.2% kernel 0.2% 1324/dmcrypt_write: 0% user + 0.2% kernel 0.1% 1840/com.android.phone: 0% user + 0.1% kernel / faults: 2 minor 0.1% 23112/kworker/0:0: 0% user + 0.1% kernel 0.1% 563/kswapd0: 0% user + 0.1% kernel 0.1% 1336/jbd2/dm-0-8: 0% user + 0.1% kernel 0% 3/ksoftirqd/0: 0% user + 0% kernel 0% 8/rcu_preempt: 0% user + 0% kernel 0% 1242/kworker/0:1H: 0% user + 0% kernel 0% 12/ksoftirqd/1: 0% user + 0% kernel 0% 1249/logd: 0% user + 0% kernel 0% 1298/servicemanager: 0% user + 0% kernel 0% 1352/netd: 0% user + 0% kernel / faults: 63 minor 0% 1434/dhcpclient: 0% user + 0% kernel 0% 22591/com.android.vending: 0% user + 0% kernel / faults: 14 minor 10% TOTAL: 5.6% user + 3.5% kernel + 0.3% iowait + 0.4% softirq CPU usage from 303ms to 808ms later (2018-12-19 17:16:23.658 to 2018-12-19 17:16:24.163): 9.9% 1641/system_server: 7.9% user + 1.9% kernel / faults: 2593 minor 7.9% 2069/Binder:1641_8: 3.9% user + 3.9% kernel 1.9% 1648/FinalizerDaemon: 1.9% user + 0% kernel 5.7% 1935/adbd: 0% user + 5.7% kernel / faults: 572 minor 1.9% 1935/adbd: 0% user + 1.9% kernel 9% TOTAL: 4% user + 5% kernel

hackyxicor avatar Dec 19 '18 11:12 hackyxicor

I have the same exact issue.

hari-devaraj avatar Dec 31 '18 09:12 hari-devaraj

@hackyxicor Hi did you find any solution or workaround?

hari-devaraj avatar Dec 31 '18 09:12 hari-devaraj

I have the same exact issue.

@hackyxicor Hi did you find any solution or workaround?

add a delay of at least 1 sec before the next action. And increase ping interval of location detection.

hackyxicor avatar Dec 31 '18 10:12 hackyxicor

I did setTimeout(this.stopTracking.bind(this), 1000). Still crashes. These are my intervals

interval: 60000,
fastestInterval: 120000,
activitiesInterval: 100000

hari-devaraj avatar Dec 31 '18 10:12 hari-devaraj

I did setTimeout(this.stopTracking.bind(this), 1000). Still crashes. These are my intervals

interval: 60000,
fastestInterval: 120000,
activitiesInterval: 100000

You have to add a timeout to any action/function call invoking just after stop tracking

hackyxicor avatar Dec 31 '18 12:12 hackyxicor

Hi,

I'm having the same issue, the app says that it's not responding after calling BackgroundGeolocation.stop() on Android. @hackyxicor I'm not calling any other function before/after calling the stop function, but are there still some other functions that I should be aware of and add a timeout for them?

I have the same intervals as hari-devaraj and the same environment as you except I'm using RN 0.55.4.

jonatanlehtinen avatar Jan 29 '19 16:01 jonatanlehtinen

Okay I'm not sure if this was clear but I tested with Oneplus 3T(running Android 8.0) and Samsung Galaxy Neo(running Android 6.0.1) and I had no problems calling the stop() function so at least for me the problem only seems to occur on simulators.

jonatanlehtinen avatar Jan 31 '19 08:01 jonatanlehtinen

@joppeel I am also having the same issue. My application not responding after calling BackgroundGeolocation.stop(). Have you found any solution? I have the Problem in real device too.

ghost avatar Feb 06 '19 12:02 ghost

@dhrupalG Hi, I'm still having the problem on a simulator so unfortunately I haven't found any solution.

jonatanlehtinen avatar Feb 07 '19 09:02 jonatanlehtinen

@dhrupalG Okay now I managed to produce this error on a real device and I solved it partially with hackyxicor's workaround(by setting timeouts), but the crash still occurs from time to time.

jonatanlehtinen avatar Feb 08 '19 11:02 jonatanlehtinen

Okay now I managed to solve this problem for good, the Android Gradle Plugin that I was using forced the application to use a version of Android SDK Build-Tools which was different from the one that was specified in this plugin's documentation.

jonatanlehtinen avatar Feb 14 '19 11:02 jonatanlehtinen

@joppeel can you post how solve this problem? I have same issue in a real device. :(

WilliamPeralta avatar Feb 27 '19 08:02 WilliamPeralta

@WilliamPeralta So I think at least in my case the issue was due to the fact that I had specified the Android Gradle plugin that I was using like this:

dependencies {
  classpath 'com.android.tools.build:gradle:3.1.4'
}

This version(3.1.4) of the plugin forced the app to use the build tools version of 27.0.3, but as I was using the experimental Android Orio support, I needed to use the version 26.0.2 of the build tools as it is defined in this background tracking plugin's documentation like this:

ext {
  compileSdkVersion = 26
  targetSdkVersion = 26
  buildToolsVersion = "26.0.2"
  supportLibVersion = "26.1.0"
  googlePlayServicesVersion = "11.8.0"
  oreoEXPERIMENTAL = "yes"
}

So by downgrading to using Android Gradle plugin version 3.0.1 fixed this problem, since it allowed me to use the correct version of the build tools. I can't say if this is the only solution to the problem or whether it's a good or bad solution(I guess it depends on the case) but this is how I fixed it :)

jonatanlehtinen avatar Feb 27 '19 08:02 jonatanlehtinen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 26 '19 08:08 stale[bot]

This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn't be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it's important. Thank you for your contributions.

stale[bot] avatar Sep 02 '19 09:09 stale[bot]

Hi

App crashes on calling Background.stop() function, please anyone help on this?

Ramesh21071993 avatar Sep 29 '19 19:09 Ramesh21071993

Adicione o seguinte em android/build.gradle:

ext { googlePlayServicesVersion = "9.8.0" }

lucassutelo avatar Oct 07 '19 20:10 lucassutelo

Clear the Application storage.

Eg3ndary avatar Dec 01 '19 15:12 Eg3ndary

Using following permission fixed it. <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

tawsifalam avatar Mar 11 '20 07:03 tawsifalam

I am still facing this issue, even after adding permission as @tawsifalam suggested didn't help. Here are my build.gradle and package configuration.

build.gradle:

buildscript {
ext {
googlePlayServicesVersion = "17.0.0"
firebaseMessagingVersion = "+"
buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}

Configuration:

BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 5,
distanceFilter: 1,
notificationTitle: 'Tracking',
notificationText: "Don't mind me just watching",
notificationsEnabled: true,
startForeground: true,
debug: false,
startOnBoot: true,
stopOnTerminate: false,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 10 * 1000,
fastestInterval: 5000,
activitiesInterval: 10000,
stopOnStillActivity: false,
url: 'http://192.168.81.15:3000/location',
httpHeaders: {
'X-FOO': 'bar',
},
// customize post properties
postTemplate: {
lat: '@latitude',
lon: '@longitude',
foo: 'bar', // you can also add your own properties
},
});

raghavdnn avatar Feb 09 '21 10:02 raghavdnn