-
Notifications
You must be signed in to change notification settings - Fork 25
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 stops when the user closes the application (iPhone). #1
Comments
Hello, I tried running this application as it is on my mobile but it stops after 7-8 minutes. I locked my phone after pressing starting the service. |
Mmm, that sounds something related to Foreground permissions in your device; even I added those permissions to the Manifest and info.plist files, you would better to check them after installing the app. I haven't tested the app with Android 11, the rest of the versions Android and iPhone in general didn't show that issue. |
Thanks, Its was helpful. After your message I ran it on Android Simulator and it worked. Also showing Notification Icon on the status bar but still doesn't work on my phone and doesn't show same notification logo on the status bar. I have Vivo V11 Pro. Any clue where I should look into to troubleshoot it? |
You could debug the app on your phone and see what's going in the NotificationHelper class; even before that, in the method OnStartCommand of the AndroidLocationService class. |
I kept looking for "Foreground Services" related issues on Chinese Manufacturer devices and Samsung and it turned out that they maintain WhiteList approach for running Foreground/Background services to enhance battery life on their devices. Company i.e. Facebook, Google already has such app categorized as Whitelist apps for their OS. Then I thought to give it a try and I deeply looked into my phone for every single setting related to Background Running Process and for Notifications. I also checked Battery Settings. And the results was after enabling your app "XamarinForms.Location" for "High background battery usage", it was able to run in background even when the screen was locked. I am digging into it more and will back. |
Running this app on a Samsung A40 worked fine and ran without issues for over half an hour until I stopped it. During that time I also ran it on my Huawei P20 Pro and it lasted less than 10 minutes each time before the OS killed it off. Both devices were unplugged and had the same amount of charge (trying to debug this is a real pain as foreground services will not be killed while the phone is plugged in) and also used the default power saving settings. Huawei is particularly bad for killing off services. There does seem to be some sort of work around for this though, check out this StackOverflow Question. |
Hiiiiiiiiii guuuuuuuuyss!! Very very very so much wonderful thanks gauravkundalwal !!! I have a Xiaomi Redmi Note 8 and the service mysteriously stops when I open other apps. After disabling the Xiaomi Battery Saver, the location service worked perfectly!
Finish! |
I have ported part of this project to my own application and am testing it. On an Android Honor 10 it seemed to me that if I start Google Maps and start navigation, the service stops. I tried to restart it and it went for a while but within 30 minutes the service stopped again (I don't know exactly at what minute because I was driving) |
Hello @Hiden46 i test this app in many config and i'm going to share my result if it's can help. On Android 10 you have multiple restrictions. It's depend of the phone and constructor. I've made several test and it look like you can't go under 25 second location retrieval (approximately). If the service ask to many times, the security of the OS kill the app responsible for that. In addition of setting a larger timewindow for retrieval, you can also try this solution : https://stackoverflow.com/a/67291554/11630806 . But even with that, the app stop in 2 hour if the phone is not plug (on android 10 only and it's depends of smartphone brand). Also, if you use another app like googleMap or Waze for exemple, the conflict between the multiple call to the location ended you're app. Hope it helps, if you find better solutions or if you have other result in test don't hesitate to share it. |
Hello @paulCrp I have left the time to request the GPS signal exactly as in the app above, every 2 seconds I make a request to get the coordinates, speed and location of the device. |
Correct me if I'm wrong but it looks like android:foregroundServiceType="location" is missing from the service / AndroidManifest? Some Android devices will kill the foreground service after a while if it is not told what it does. https://developer.android.com/guide/topics/manifest/service-element |
Hi @ormesam I tried as you wrote to put the tag in the manifest, referring to the service inside the Android part, but nothing has changed. I am currently doing some tests and shortly after the application goes in the background it stops getting the gps signal. It starts over as I reopen it. |
Hi @Hiden46 did you add the [Register("...")] attribute to the service too? This is how I do it in one of my projects: Service AndroidManifest
|
@ormesam Yes I did. I have noticed that if I try using visual studio debugging with cable phone connected the service continues to work. When I try the app instead without being debugged with visual studio and unplugged the phone from the PC it stops working after a while. The active service icon remains, but you notice that the GPS system is not working because the icon does not appear in the status bar. I put the Register in the |
No description provided.
The text was updated successfully, but these errors were encountered: