-
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
How to keep HTTP requests running in background? - Android #14
Comments
May I ask what device(s) you are experiencing this issue with? As a starting point, could you please insert |
Samsung Galaxy Tab A SM-T510 on Android 10. I made a quick test editing the Android plugin code, and put an additional HTTP POST call inside the onLocationResult() callback method. Then after 5-10 more minutes, I stop getting the Axios call, but keep getting the native one, which is what I want to achieve anyway. So I guess I'll just fork this. |
There looks to be some throttling going on. The plugin seems to receive location updates every ~10s initially, slowing to one per minute or less. So the operating system might be throttling updates from the location provider to the plugin. But it also looks like the operating system is throttling execution of the WebView, which is disturbing (however I can't tell from your logs whether the watcher callback ceased being called or was just unable to send off HTTP requests). |
Where do the timestamps in the rightmost column come from? Are they from the location object, or generated by the server? |
That's the timestamp from server, when it receives the request. |
Thanks. It might be illuminating to see the difference between the time the location was generated and the time it was received by the server. |
So this is what I got in Android Studio console (couldn't use Chrome devtools). Finally, when I open the App again, it starts to fire off all queued requests, and logs the following to make it clear: In conclusion, seems like this is intended by Chrome and I don't pretend my users having to turn this off, so I guess native HTTP is the way to go 👍🏻 |
From the link you pasted above, it appears your Axios requests should not be throttled.
The error message seems to indicate that your requests are not receiving responses. Are you sure your server is responding to your requests correctly? |
Oh I totally missed that. You're right. |
Is it possible your server is accepting & processing the requests, but is not sending out any response? |
Just tested this by putting a log server-side, right before returning the 200 response. It definitely sent the response back. |
Well I am bamboozled then. |
Yeah, thanks for keeping in touch. |
I am experiencing this issue on Android only exactly as described in the opening post of this thread, I implemented an enqueueing process which I initially thought helped, but then on Android the problem (as described above) persisted. I considered setting up job queueing on my Laravel backend, but that doesn't rectify the fact that after some time Android appears to start spamming GPS locations after adding them up -- it's almost as if backgrounding works temporarily, then stalls, collects GPS to send but doesn't use the callback to send them until the app is foregrounded - then it spams all of the GPS points into your database all at once, causing throttling to occur. @JuanDeLeon did you solve this somehow? |
@gbrits Yeah I switched from Axios to the Http plugin for this specific call. So on this plugin's callback I do:
And this method will use Http community plugin, not axios.
|
Hey thanks for responding @JuanDeLeon I'm seriously keen to get this fixed, thanks for sharing your code. I'm using Ionic, I'm not using Axios (as far as I'm aware) I'm using |
I see you're referring to https://github.com/capacitor-community/http -- @angular's common http must be a javascript implementation of http requests, much like Axios, whereas it appears |
Yeah should be the same root issue. You want native http, not browser based. After switching to native http, I kept my tablet turned on for 12+ hours and definitely worked as I expected. |
If you need a quick try, you may overwrite this plugin's native callback function and add something like the following.
|
Thank you so much! I will give it a whirl |
You saved my day! |
Hi! I'm currently maintaining a fork of mauron85 plugin and am looking into migration to capacitor. I generally don't need all this http stuff but am interested to know how to solve the current problem of webview being stopped while the app is in the background (the 5 minutes described in this issue). |
@diachedelic any comments on the above question? |
This issue is about HTTP requests being throttled in the background. As far as I am aware, the WebView does not stop after 5 minutes in the background. Please create a new issue if that is happening for you. |
Thanks for the info @diachedelic! |
The sum up, HTTP requests initiated within the WebView are not sent reliably in the background. To fix this, use a native HTTP plugin such as https://capacitorjs.com/docs/apis/http. |
First of all, awesome plugin. Now, I understand this is not exactly a plugin's issue, but probably a very common scenario for it.
I'm trying to watch and send the location via HTTP Post request to server as in the following code:
This is working fine in iOS indefinitely (as long as I grant the 'Always' location permission).
However for Android, this is not the case. I granted all battery/data usage permissions for my app in particular.
After 5 minutes in background, the server will stop receiving locations.
As soon as I enter the app again (it is not being killed btw, I can tell because it does not reload the splash screen) it will start sending all the buffered requests to server.
So the location is being tracked correctly, but it seems like the HTTP requests get blocked and start to pile up.
Does this mean that I should actually do the HTTP request inside the native callback code?
public void onLocationResult(LocationResult locationResult)
I would appreciate any insight, but as I said, I understand this is not precisely this plugin's issue.
The text was updated successfully, but these errors were encountered: