Android Question StartServiceAt good practice

CaptKronos

Active Member
Licensed User
Longtime User
I am using the approach that Erel describes for Background Location Tracking but was wondering whether there are any issues with setting StartServiceAt with a value sooner than 30 minutes (e.g. 2 minutes) so there is less gap with tracking if the OS kills the process?
 
but was wondering whether there are any issues with setting StartServiceAt with a value sooner than 30 minutes (e.g. 2 minutes)
Yes. Android will not allow it.
Your app probably gets killed within a few minutes.
If you upload the app to playstore you probably have no other choice.
 
Upvote 0
Thanks. So it shouldn't be less than 30 minutes? Is there any documentation that describes this? I couldn't find any.
 
Upvote 0
Thanks. So it shouldn't be less than 30 minutes? Is there any documentation that describes this? I couldn't find any.
You can read about it here: https://developer.android.com/reference/android/app/AlarmManager#setexactandallowwhileidle
and here: https://developer.android.com/training/scheduling/alarms#java
As Erel said it may not work well on some of the devices, but I have never had a problem with Samsung devices that I used to start service at repeating times less than 30 minutes - from the links above, I think that it is not really an Android API limitation, but may be phone manufacturer in order to increase battery life.
 
Upvote 0
Thanks all. I have been using a period of 15 minutes without seeing a problem but I'll move to 30 minutes.
 
Upvote 0
For the devices that seem to limit intervals to 30 or more mins, I wonder if those devices are smart enough to limit *anything* in the app from running less then 30 minutes apart, or does it just limit a particular service from running less then every 30 mins?

Because if it only limits a particular service, then theoretically you could have 6 different services setup to run at different 30 min intervals (separated by 5 mins), and when each of the 6 services are triggered, they could then call some central routine that does the actual work of the app. So in a sense, these 6 services would be just dummy services.

If this is true, then this could mean you could get your app to reliably run every 5 mins even on devices that try to limit each service to no less then 30 mins.
 
Last edited:
Upvote 0
What is interesting is what an antivirus application like AVG does with that. It looks at the behavior of an application and can label it as malware because yes, it comes from one application.
 
Upvote 0
What is interesting is what an antivirus application like AVG does with that. It looks at the behavior of an application and can label it as malware because yes, it comes from one application.
If it were windows, I would probably agree.

But with Android's sandboxing, I don't think apps can monitor another apps actions without root privileges, but I could be wrong on this.

I always wondered how effective anti-virus apps are on android devices because they can't hook into the OS as deeply as they can in windows.
 
Last edited:
Upvote 0

Similar Threads

Back
Top