Marcos Alves Well-Known Member Licensed User Longtime User Jul 24, 2018 #1 Hello all, Is there any way to automatically start a service when the internet connectivity is back after a period down?
Hello all, Is there any way to automatically start a service when the internet connectivity is back after a period down?
DonManfred Expert Licensed User Longtime User Jul 24, 2018 #2 No. You need to have a running service to get this information at all. There is no event for this in Android. Edit: https://developer.android.com/training/monitoring-device-state/connectivity-monitoring#java Probably possible using a Broadcastreceiver. But the receiver must be started in a service and the process must still be active if i read it right. So i guess it will not work if your app is killed/not started Last edited: Jul 24, 2018 Upvote 0
No. You need to have a running service to get this information at all. There is no event for this in Android. Edit: https://developer.android.com/training/monitoring-device-state/connectivity-monitoring#java Probably possible using a Broadcastreceiver. But the receiver must be started in a service and the process must still be active if i read it right. So i guess it will not work if your app is killed/not started
Marcos Alves Well-Known Member Licensed User Longtime User Jul 25, 2018 #3 DonManfred said: No. You need to have a running service to get this information at all. There is no event for this in Android. Edit: https://developer.android.com/training/monitoring-device-state/connectivity-monitoring#java Probably possible using a Broadcastreceiver. But the receiver must be started in a service and the process must still be active if i read it right. So i guess it will not work if your app is killed/not started Click to expand... Hello Don, thanks for answering (again ). This resource could be very interesting for the situation when an app uses the internet to receive or send instant messages or other real time data that could be queued in background in moments without internet. Instead of maintaining a service running, if we could program a service that wakes up whenever the connection is reestablished after a down period, we could save battery and increase a lot the app efficiency doing the dispatch near instantly when reconnected. I think that should have any way to start a service when connectivity is up, similar to push messages but with a "local flag to android"... I'll study the article to find is there is a way and post here if find anything. Thanks! Upvote 0
DonManfred said: No. You need to have a running service to get this information at all. There is no event for this in Android. Edit: https://developer.android.com/training/monitoring-device-state/connectivity-monitoring#java Probably possible using a Broadcastreceiver. But the receiver must be started in a service and the process must still be active if i read it right. So i guess it will not work if your app is killed/not started Click to expand... Hello Don, thanks for answering (again ). This resource could be very interesting for the situation when an app uses the internet to receive or send instant messages or other real time data that could be queued in background in moments without internet. Instead of maintaining a service running, if we could program a service that wakes up whenever the connection is reestablished after a down period, we could save battery and increase a lot the app efficiency doing the dispatch near instantly when reconnected. I think that should have any way to start a service when connectivity is up, similar to push messages but with a "local flag to android"... I'll study the article to find is there is a way and post here if find anything. Thanks!
Peter Simpson Expert Licensed User Longtime User Jul 25, 2018 #4 Just use a service to test for internet connectivity every so often, when there's internet connectivity just do whatever you need your app to do... Upvote 0
Just use a service to test for internet connectivity every so often, when there's internet connectivity just do whatever you need your app to do...
Marcos Alves Well-Known Member Licensed User Longtime User Jul 25, 2018 #5 Peter Simpson said: Just use a service to test for internet connectivity every so often, when there's internet connectivity just do whatever you need your app to do... Click to expand... Hello Peter... Ok, I can schedule a service each, let's say, 30 seconds... but imagine: - Running each 30 seconds will clearly spend more battery than a service called by push, for example. - In an unstable connection, the time when service starts could not be the same time frame when the internet is available (this is very significant, for example, when I have to send a small message with a few bytes and only 5 or 10 seconds of connectivity could be enough). - And finally, in messenger services like those that we manage here it's very common to have two users testing the messages efficiency putting two mobile devices side by side and checking how much time a remote system will spend to receive a message after internet connection... 30 seconds is A LOT in this cases. Of course that the use of Firebase Cloud Messages increases the response efficiency for incoming messages due the push function starting the services, but for queued outgoing messages I cant see other way instead of maintaining a foreground service while there is queue... and this is not good because I have reports from many users about the "dislike" of persistent apps notifications... I'll study a little bit more and post here if I find new solutions. Upvote 0
Peter Simpson said: Just use a service to test for internet connectivity every so often, when there's internet connectivity just do whatever you need your app to do... Click to expand... Hello Peter... Ok, I can schedule a service each, let's say, 30 seconds... but imagine: - Running each 30 seconds will clearly spend more battery than a service called by push, for example. - In an unstable connection, the time when service starts could not be the same time frame when the internet is available (this is very significant, for example, when I have to send a small message with a few bytes and only 5 or 10 seconds of connectivity could be enough). - And finally, in messenger services like those that we manage here it's very common to have two users testing the messages efficiency putting two mobile devices side by side and checking how much time a remote system will spend to receive a message after internet connection... 30 seconds is A LOT in this cases. Of course that the use of Firebase Cloud Messages increases the response efficiency for incoming messages due the push function starting the services, but for queued outgoing messages I cant see other way instead of maintaining a foreground service while there is queue... and this is not good because I have reports from many users about the "dislike" of persistent apps notifications... I'll study a little bit more and post here if I find new solutions.