Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background service not running on first call #103

Open
donettech opened this issue Jun 30, 2021 · 6 comments
Open

Background service not running on first call #103

donettech opened this issue Jun 30, 2021 · 6 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@donettech
Copy link

donettech commented Jun 30, 2021

I implemented this package to get background location, However, the service won't start on the first call and performs normally on the second and following calls.

`ElevatedButton(
child:Text("Start),

onPressed()async{
await bg.BackgroundLocation
.setAndroidNotification(
title: 'Background service is running',
message:
'Background location in progress',
icon: '@drawable/ic_notification',
);
await bg.BackgroundLocation
.setAndroidNotification(
title: 'Background service is running',
message:
'Background location in progress',
icon: '@drawable/ic_notification',
);
//await BackgroundLocation.setAndroidConfiguration(1000);
await bg.BackgroundLocation
.startLocationService(
distanceFilter: 200);
await bg.BackgroundLocation
.startLocationService(
distanceFilter: 200);
bg.BackgroundLocation.getLocationUpdates(
(location) {
print("Location updated"+location.toString());
});
}
)`

When clicked on the button that calls the service, no error is printed and works fine when clicked for second time.

My flutter doctor is below

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.0.6, on Microsoft Windows [Version 10.0.14393], locale en-IN) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [√] Chrome - develop for the web [√] Android Studio (version 4.1.0) [√] VS Code (version 1.57.1) [√] Connected device (2 available)

@luis901101
Copy link
Contributor

luis901101 commented Jul 2, 2021

Same happen to me. This bug began in version ^0.6.1, before that version the notification starts at the first call.

@luis901101
Copy link
Contributor

luis901101 commented Jul 2, 2021

Digging a bit more I found that the issue is not only the notification not showing at first call but also the background location not starting.
When app goes to background the notification should startForeground as an ongoing notification (to ensure intent service long live), and background location listener should acquire GPS. When all of this is OK then the app notification shows up and the GPS symbol shows up as well proving the app is in deed receiving background locations.
In version 0.6.1 this is not working well.

Some examples for better understanding of the issue:

  • App working fine using version 0.6.0 View example. Note when app goes to background the notification and GPS symbol shows up immediately.
  • App not working using version 0.6.1 View example. The code is exactly the same as previous example, note when app goes to background nor the notification nor GPS symbol shows up.
  • App not working using version 0.6.1 with notification workaround View example. Here the only change in code is calling the notification twice, note when app goes to background the notification shows up but GPS symbol does not.

Note 1: the app in the examples uses geolocator ^7.2.0+1 for foreground locations
Note 2: In iOS everything is working as expected

@blaqkrow
Copy link

blaqkrow commented Jul 4, 2021

Hey man so if you switch back to 0.6.0 it worked? Im having trouble receiving callbacks when I navigate away from the app and into the background. Heres my code: https://github.com/blaqkrow/location_tracking_flutter

@luis901101
Copy link
Contributor

Hey man so if you switch back to 0.6.0 it worked? Im having trouble receiving callbacks when I navigate away from the app and into the background. Heres my code: https://github.com/blaqkrow/location_tracking_flutter

Yes, using version 0.6.0 works fine, to ensure using that especific version you should set background_location: 0.6.0 in your pubspec, the tip here is not to use the ^ at the begining of the version.
I see in your code you don’t set the Android notification, I recommend you to set it, as described in the README of this plugin, await for the notification and then start location service.

@DevTiago
Copy link

The answer from @luis901101 saved my day: just change the version from pubspec.yaml from ^0.6.1 to 0.6.0

@Almoullim Almoullim added bug Something isn't working help wanted Extra attention is needed labels Sep 28, 2021
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Jul 24, 2023
@Almoullim Almoullim self-assigned this Jul 25, 2023
@Almoullim Almoullim removed the stale label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants