-
-
Notifications
You must be signed in to change notification settings - Fork 77
Android 8 Background service does not work while app is suspended #157
Comments
Hey, From SDK 26 and above, the background services changed radically. The demo on this repo isn't prepared for SDK 26. I've been working on background services for this plugin for a while now. I'm using Nativescript-Vue but hopefully with the following code you will get the jest of what needs to be done.
On the manifest.xml:
From here on, you just need to call the service on any part of the app that you need...
I have a working {N}-Vue demo proyect that I could share if someone needs it, it has background services for both iOS and Android (for both pre SDK26 and post SDK26). Just let me know. Edit: Added calling services code |
Hi @Raxidi , Thank you for bringing this to our attention. @rigoparis Thank you for providing an solution approach, I have made changes to the demo app using this approach and a PR. @Raxidi You can see the changes in my PR that enable the use of background service on API level 26 and above here |
@rigoparis Thanks a lot for your help and guidance. I'm sorry for replying late. @VladimirAmiorkov Thank you for the updated demo app. I tried the updated version of demo background service. I'm sorry to say that location updates were not working when app was in suspended mode. It looks like any service which runs in background are affected by android power saving/doze mode optimizations. I tried running the service as Foreground Service by creating android.app.Notification object with default constructor. Now I am able to get continuous updated in toaster alerts even when app is suspended. However I get notification alert saying "app is running in the background - Tap for details on battery and data usage"(i'm fine with this alert for my app). I am not sure the way I use the service is good practice or not. Below are the changes I had to make to get this app running. Here are the changes in different files: File: background-service.ts
File: main-page.ts
File: AndroidManifest.xml
Please let me know what I am doing is correct or not. |
Implemented in the demo app. |
Hi @rigoparis . I was just trying to work with background services in {N}-Vue and really having a hard time. Can you still share your code? |
Hey @andreMariano90 sure thing man, I'll try to upload it tomorrow since I don't have the laptop I have that in with me. Sorry for the late response, got distracted before |
Thank you! |
Hey @andreMariano90 Just uploaded the repo https://github.com/rigoparis/GeolocationNativescriptVue If you have any issues, please let me know... Just keep in mind that Android's background services can run at minimum every 15 minutes (up to what I've researched, this is due to battery restrictions). Also on this demo you might encounter this error: I'll try to tweak it to bring it up to date and make everything work again 100%, but the jest remains the same and it's working on a production app I have that uses Geolocation |
Hey @Raxidi Sorry for the super late response. I checked the code you pasted and noticed that you only have 1 service declared on the manifest Remember to declare the 2 services like so:
That should get you up and running as everything else seems fine. |
WOW! Thank you! Sorry for restarting this closed topic! |
Somehow my app crashes after certain duration of inactivity. Anyways thanks @rigoparis for all the help. Cheers!! |
Hey @Raxidi!
It's my pleasure to help. If you want, you can create a sample proyect and
I'll check it out.
On Dec 26, 2018 5:32 AM, "Akshara Raxidi" <[email protected]> wrote:
Somehow my app crashes after certain duration of inactivity. Anyways thanks
@rigoparis <https://github.com/rigoparis> for all the help.
Cheers!!
Akshara
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#157 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVcYedyNa_pRNnAQY3PLnFSH-IV4QSJuks5u815lgaJpZM4WTXr5>
.
|
If any one is interested in how to do this in the angular demo, I've done like so:
Declared the service inside AndroidManifest.xml application tag as such:
Created a helper class to use inside standard angular components called foreground.service.util.ts
Added the following in home.component.ts
|
Hi @vakrilov...could you plz share this angular demo of notifications in the background. |
Hey @nisha-ann, |
yes i guess.@vadimhoratiu..could you plz share a demo in angular nativescript |
Hi @nisha-ann The files that I've written above is all you need.
That should be it, if you still have issues I'll try to see if I still have the code somewhere and upload it here. |
Thankyou so much..let me try and I'll reply if there is any issue |
Hi there @vadimhoratiu I've tried to use foreground but |
@heydershukurov01 Hi, did you declare class |
@heydershukurov01 Have you resolved this issue |
Hi..I used a worker thread instead of background services and captured the
resume event to make changes as the resumes.
For me it works fine now.
…On Thu, Aug 1, 2019, 8:00 AM d-mh, ***@***.***> wrote:
@heydershukurov01 <https://github.com/heydershukurov01> Have you resolved
this issue java.lang.RuntimeException: Unable to instantiate service
com.tns.ForegroundService: java.lang.ClassNotFoundException: Didn't find
class "com.tns.ForegroundService"...? If yes could you send solution?
Thanks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#157?email_source=notifications&email_token=AL3XDAE23LCER3JFQE64JATQCLF4TA5CNFSM4FSNPL42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3KK7II#issuecomment-517255073>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AL3XDADNABUJ542LSKWH4XLQCLF4TANCNFSM4FSNPL4Q>
.
|
Hi, |
Hi @jrkf , Take a look at the current demo applications which showcase how to use a background worker on Android: https://github.com/NativeScript/nativescript-geolocation/blob/master/demo/app/background-service.ts#L42-L96 |
Fixed for nativescript 6.1.0 Delete the following if present
Re-run npm install, tns run android |
Is there a working solution for Nativescript Vuejs to foreground track the geolocation? I didnt manage to fix those old solutions. Would be awesome. |
I've updated the foreground service to run it on AndroidX.
|
If the demo apps cannot help and there is no issue for your problem, tell us about it
I am using just the demo app with no changes.
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with:
{
"nativescript": {
"id": "org.nativescript.LocationBG",
"tns-android": {
"version": "4.2.0"
},
"tns-ios": {
"version": "4.2.0"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN ",
"repository": "",
"dependencies": {
"nativescript-geolocation": "^4.3.0",
"nativescript-theme-core": "~1.0.4",
"nativescript-toast": "^1.4.6",
"tns-core-modules": "~4.2.0",
"tns-platform-declarations": "^4.2.0"
},
"devDependencies": {
"nativescript-dev-typescript": "~0.7.0",
"nativescript-dev-webpack": "~0.15.0",
"typescript": "~2.7.2"
},
"readme": "NativeScript Application"
}
Please, tell us how to recreate the issue in as much detail as possible.
Describe the steps to reproduce it.
Take the demo app from this repo. Build and install it in device having Android 8. WatchLocation fires only when app is in foreground.
This might be due to background process limitation in Android 8. I am new to Nativescript/Typescript and have no idea about using it as a Android Bound service(Android documention says Bound Service doesn't have the limitation).
I just want to get the location changes even when app is in suspended mode in Android 8.
Please help.
Is there any code involved?
App.zip
The text was updated successfully, but these errors were encountered: