question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Demo app doesn't record/track location when app is suspended

See original GitHub issue

Which platform(s) does your issue occur on?

  • Android
  • Android versions 8/9
  • Samsung Galaxy S7 device and Google Pixel 3 API 29 Emulator

Please, provide the following version numbers that your issue occurs with:

  • CLI: 6.0.2
  • Cross-platform modules: 6.1.1
  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)
  • Plugin(s):

“nativescript”: { “id”: “org.nativescript.demo”, “tns-ios”: { “version”: “6.1.0” }, “tns-android”: { “version”: “6.0.2” } }, “dependencies”: { “nativescript-geolocation”: “…/src”, “nativescript-theme-core”: “^1.0.4”, “nativescript-toast”: “~2.0.0”, “nativescript-unit-test-runner”: “0.7.0”, “tns-core-modules”: “^6.0.0” }, “devDependencies”: { “jasmine-core”: “^2.5.2”, “karma”: “4.1.0”, “karma-jasmine”: “2.0.1”, “karma-nativescript-launcher”: “^0.4.0”, “nativescript-css-loader”: “~0.26.0”, “nativescript-dev-webpack”: “^1.0.0”, “tns-platform-declarations”: “^6.0.0”, “tslint”: “~5.11.0”, “karma-webpack”: “3.0.5”, “typescript”: “~3.4.5” },

Please, tell us how to recreate the issue in as much detail as possible.

Run the demo app and start background thread monitoring. Then press home (suspend the app) and change location. Location is only recorded when you re-enter the app.

I assume this is supposed to run location tracking in the background i.e. when the app is suspended. If so I cannot get this to work on both the emulator and device provided above. Location services stops running.

Is the demo app supporting background location tracking? If not how would this be achieved in Nativescript Angular on Android?

Is there any code involved?

Demo app of this repo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
Aceman18commented, Oct 17, 2019

@Basler182 and anyone else who checks this out. I have found a solution based around using a foreground service. It is based on this NativeScript/NativeScript#6994

This issue has been solved but also contained a demo project. I have updated that demo project to NS6.

There was also a fix needed for the webpack.config.js file I added this below based on this answer: https://stackoverflow.com/a/57757216

Before: const appComponents = [ “tns-core-modules/ui/frame”, “tns-core-modules/ui/frame/activity”, ];

After: const appComponents = [ “tns-core-modules/ui/frame”, “tns-core-modules/ui/frame/activity”, resolve(__dirname, “./src/foreground-service.android”) ];

Here is the updated demo project: ns6-updated-foreground-service.zip

1reaction
Aceman18commented, Oct 17, 2019

@snackmaster95 Hi, unfortunately I don’t personally have any VueJS experience so I won’t be able to help specifically there.

However this solution only adds javascript/typescript to the project, so as far as I know there shouldn’t need to be anything Vue specific? The files that are changed are webpack.config.js, androidManifest.xml, app.component.ts (or the root of your app), references.d.ts (if you don’t have this just add it) and then the foreground-service.android.ts. If I’m correct this can all be translated into VueJS compatible files, but like I said my experience is limited?

The “date second” console log is located in the items.component.ts file

Read more comments on GitHub >

github_iconTop Results From Across the Web

Location update after suspending the app from background #6
I have installed ARC app and suspended the app. But still I was able to see you were tracking user location. How you...
Read more >
Continuous location in background … | Apple Developer Forums
I am writing an iOS app that requires continuous location updates while being in the background. I am using CLLocationManager and here is...
Read more >
Get Location Updates for iOS App Even when Suspended
Yes, even when the app is killed/suspended either by the user or iOS itself, you still can get the location updates.
Read more >
How to run code when your app is terminated
How to run code when your app is terminated · Background fetch will let your app run in the background for about 30...
Read more >
Getting Location Updates for iOS 7 and 8 when the App is Killed
In iOS 7.0, Apple prevents the location update when the app is killed/terminated/suspended. But, Apple has fixed the “bug” starting from iOS 7.1 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found