Android Question Send the data to the server while the app is not active

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I have a question. Is it possible to send the data to the server while the app is not active? For example - user has left the app for a few hours and while the app isn't active (I mean all the activities are paused) - send the data back to the server? Or this app will be rejected?

Why I'm asking - for example the user has clocked in but didn't clock out for any reason and won't touch the app for 2-3 days - that means that the data won't be sent to the server until this user will return to the app again. So the idea is to send it behind the scene.
 

JohnC

Expert
Licensed User
Longtime User
Create a routine called "WatchDog" that sets a StartServiceAt schedule for one hour in the future that will run a service called "LogoutandUpload".

Then everytime the user does some type of interaction in your app, call the "watchdog" routine - this will have the effect of constanly kicking the time of the startservice more and more in the future, so it never gets a chance to trip if the user is actively using the app.

Then, when the user stops using the app, after an hour, the startservice will trip and run the service, and this service could then possibly log the user out automatically, then submit the data to the servicer.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Create a routine called "WatchDog" that sets a StartServiceAt schedule for one hour in the future that will run a service called "LogoutandUpload".

Then everytime the user does some type of interaction in your app, call that routine - this will have the effect of constanly kicking the time of the startservice more and more in the future, so it never gets a chance to trip if the user is actively using the app.

Then, when the user stops using the app, after an hour, the startservice will trip and run the service, and this service could then possibly log the user out automatically, then submit the data to the servicer.
Thank you for the idea.

I already have a timer in the Starter that on each tick checks if all the activities are paused. If so - it waits for 20 minutes and log the user out. It works for years and Google doesn't have any questions. But if I before the log the user out will start sending the data behind the scene - will it be Ok in the light of the new Google policy?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
How long does it take to upload the data?

Are you talking about the new requirement to use a reciever instead of a service? If so, then it is my understanding that receivers are not gauranteed to "run" for a long period of time, so that could be an issue if the data takes a log time to upload.

But as far as doing a startreceiverat call to run something in the background, I am not aware of any google policy against that - do you have a link to this google policy you are concerned with?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
35-40 seconds, may be less if the phone is new, like Samsung S23. Android 10 phones - 35 seconds
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You might need to do a wakelock in the receiver to keep it alive during the upload, but I am not sure.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you might want to check this:
https://developer.android.com/training/monitoring-device-state/doze-standby

among other statements there:

If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.

you don't mention which version of android your users are running; behavior may be different, depending.
 
Upvote 0
Top