-
Notifications
You must be signed in to change notification settings - Fork 57
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
Capacitor 4 after 5 minutes stop working #89
Comments
Are you using the native HTTP plugin to send your POST requests? See #14 (comment). |
Yes, in both versions (@capacitor 3.6.0 and @capacitor 4.6.1 ), I used native requests from CapacitorHttp, example: if (window.navigator.onLine) { |
Can you reproduce this using the app in the |
I believe so, but only tomorrow, then I'll let you know |
In app from the example/ directory when i generated apk by android studio, it worked correctly in the background for 5 minutes, but then it stopped, I didn't even change the code, could it be that something was missing? |
I got the same problem. It was working perfectly before I updated to capacitor v4 and it stopped working. Right now it stops after 5 minutes. And yes I am also using HTTP to make requests. Anyone that knows a fix? |
Is this affecting iOS, or just Android? |
Only android. On iOS it is working fine. I had this same problem a while
ago on version 3but that was because I was using axios.
Op vr 3 feb. 2023 om 22:30 schreef diachedelic ***@***.***>
… Is this affecting iOS, or just Android?
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANMF7O3JKEZCGGYSUS2H3CDWVV2ILANCNFSM6AAAAAAUPKN4FU>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Were you using the same version of this plugin for both Capacitor v3 and Capacitor v4? I just want to be sure that it's not a bug I introduced recently. |
I tried 2 things. First on version 1.2.6 and then 1.2.7. Both not working.
Op vr 3 feb. 2023 om 23:10 schreef diachedelic ***@***.***>
… Were you using the same version of this plugin for both Capacitor v3 and
Capacitor v4? I just want to be sure that it's not a bug I introduced
recently.
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANMF7OY6AOWEYFKIQLS3WGDWVV64NANCNFSM6AAAAAAUPKN4FU>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Try setting some breakpoints around Line 96 in c6e5010
|
You want to talk trough discord? Add me if you want:
Add me on https://discord.com/ so we can talk! My username is Samy#1851.
Op vr 3 feb. 2023 om 23:34 schreef diachedelic ***@***.***>
… Try setting some breakpoints around
https://github.com/capacitor-community/background-geolocation/blob/c6e5010663fc0f0da3b87f26e4c39560093edf9e/android/src/main/java/com/equimaps/capacitor_background_geolocation/BackgroundGeolocationService.java#L96.
We must determine whether the issue is with the location provider, or
communication with the WebView.
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANMF7O5OA2LH3NAX65M2DZ3WVWBYFANCNFSM6AAAAAAUPKN4FU>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
I did this in the example, and from what I noticed, it continues to capture the values, but after 5 minutes it stops sending to the application but continues capturing, if we open the app again, leaving to the background, it sends everything that it captured all at once. https://drive.google.com/file/d/1XOIMpzMi_0tC_Tawal90O0hAZ9iDBTqI/view?usp=share_link |
It seems that the operating system is suspending execution of the WebView. Have you ensured battery optimisation is turned off? See https://dontkillmyapp.com/. It seems strange that upgrading to Capacitor 4 would cause this. |
I had that in the previous version. I might have deleted it by accident. I
will try it and let you know. I tried to set the settings on the phone to
allow all battery usage the app needs.
Op ma 6 feb. 2023 om 22:24 schreef diachedelic ***@***.***>
… It seems that the operating system is suspending execution of the WebView.
Have you ensured battery optimisation is turned off? See
https://dontkillmyapp.com/. It seems strange that upgrading to Capacitor
4 would cause this.
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANMF7O6XNLTUTHGVEA5W2ALWWFTXLANCNFSM6AAAAAAUPKN4FU>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
I resolved my problem, it was probably a structural problem, i removed all my code and did it based on the example, some imports changed too, here's how the code made in typescript was in case anyone needs it. ` async addWatcher(background: boolean): Promise {
}` |
I'm not sure that will have resolved your problem. Above your comment there is a reference to a bug report for Capacitor 4, which makes it look like we need some kind of workaround like this to prevent the WebView going to sleep in the background. @Samy-F , do you want to see if you can implement this fix? |
I believe it's not a problem with the background-geolocation plugin, because I'm managing to send Post now normally for as long as I want, and I'm on the latest version of both the capacitor and the geolocation plugin, but I admit that I don't know what the problem really was, I simply deleted everything I had and redid everything again. |
OK, I'm glad you got it working. I will leave this issue open because it seems others are having the same problem. |
Hi, sorry by my english |
Can you replace the
|
Thanks for all your work ! I suggest to add the following permissions :
EDIT : ok, I add an issue (no service triggered and no notificatio, using Capacitor 4), now when I add ACCESS_BACKGROUND_LOCATION the notification is OK. I will try the background behavior using this notification. If you want I can create a PR ! |
That is interesting, but I don't see how can be a permissions problem. The locations are being recorded in the background, but they are only reported to the WebView when the app comes to the foreground again. Also, on Android, we do not technically record locations in the "background" (see #58 (comment)), so the ACCESS_BACKGROUND_LOCATION should not be necessary. The FOREGROUND_SERVICE permission is already requested in the plugin's AndroidManifest.xml. I wonder if the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS has something to do with it - but from my understanding, that is just a convenient way to disable battery optimizations, which can be done via the settings anytime).
Which example is this?
Can you please link to this issue? Are you using this plugin, a different plugin, or both? |
same issue for me in android pixel 5 |
same happens for me @ghimarcos how you fixed it? |
Please test that this is fixed in v1.2.12. |
@taivo-digiex Ensure you add any background watchers while the app is still in the foreground. |
Yes, I have. I'm using your example code and it working in background for about 5m before stop |
Is your app sending each location in an HTTP request? Can you reproduce the problem using the demo app in the |
My app just received location's object and not sending to any database. Sorry if I misunderstand your first question Is the |
@taivo-digiex The By lightly modifying the |
@taivo-digiex Does the notification remain after 5 minutes, or does it disappear? |
Thanks @alexandermccormick. I will try it |
Its still appear with location icon on status bar. Btw, I have a case when I modified handleOnPause() I had to add the background location permission. If not the app will stop all |
When your application receives a location update, what does it do with it? Does it save it to disk? Display it on the screen in some way? How do you know exactly that it is stopping after 5 minutes? |
@diachedelic my app is getting location to show on screen only. I have used console.log(new Date)/count i++ to know when it stop on Android studio terminal |
OK. Please try to reproduce your problem using the app in |
hi @diachedelic , I just run your example with only add console.log(new Date()) in log_locaiton() and modified packages.json for match with windows command |
Have you disabled all battery saving optimizations on your phone? Please try doing that via the Settings app, and if that doesn't fix the problem follow the instructions at https://dontkillmyapp.com/hmd-global. |
yes, I have disabled battery saving optimizations and set example app to unrestricted. I have tested on Samsung A52s Android 13 and it's happened too |
I believe the OS is probably suspending the app, rather than killing it entirely. Are you able to confirm? |
I don't know how to confirm that correctly, but the OS may just suspend the app as you said. As I mentioned before when I modified the handleOnPause() like your comment and added background location permission and it works perfectly |
I have attempted to reproduce the problem on my Samsung A52, running Android 13. Initially, locations stopped after one minute in the background. But after changing battery optimizations to "Unrestricted" the locations keep coming. How can it be that we are running the same app, on the same device, with the same operating system and the behaviour is different? |
let's me check with other devices, and I will let you know the result later |
@diachedelic I tried to add more details, you can look at my comment : ionic-team/capacitor#6234 |
Possibly related: https://developer.chrome.com/blog/timer-throttling-in-chrome-88/#intensive-throttling Thanks @nemoneph . |
Added a comment with a "solution" here: ionic-team/capacitor#6234 (comment) ghimarcost was write, the bug has been introduced since Capacitor 4.0 => https://github.com/ionic-team/capacitor/releases/tag/4.0.0 "android: Use addWebMessageListener where available (ionic-team/capacitor#5427) (c2dfe80)" |
@nemoneph has found a workaround for this problem: simply set |
I added android.useLegacyBridge = true but still having the same issue. |
@mohamadnagi Have you found any solution? |
Can you describe your problem? I think I can help you. I have had a lot of
problems while making my app where the user location is a crucial part of
the app.
Op wo 11 sep 2024 om 18:59 schreef giulia3ferri ***@***.***>
… @mohamadnagi <https://github.com/mohamadnagi> Have you found any solution?
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANMF7O7H55BUVP65K2L7B7DZWBZFXAVCNFSM6AAAAABOBMUFFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBUGIYDEMJRGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Describe the bug
I have an application that was previously on Capacitor version 3.6.0, and it worked perfectly. So we need to update Capacitor to version 4.6.1 and now it always stops working after 5 minutes in while the application is in Background.
To Reproduce
create an application with the following libs:
Remembering that the same code with these lib versions here work perfectly sending POST for more than 5 minutes:
The text was updated successfully, but these errors were encountered: