I have an app, with a Service
that is supposed to run all the time, and for some fixed periods of time, to send a notification to the user informing him of an available action. So if the service runs fine without being killed its ok, but if the phone runs low on memory and stops the Service, first of all, it doesnt even enter in the onLowMemory
method of the service, and even though in the onStartCommand
i am returning START_STICKY, the service isnt being recreated again any time soon..... So first of all, how can I make the service tell Android that it should be started again when memory is available, and if this is the right approach at all, to fire the notifications with a Service, or should I use some other class like AlarmManager?
Asked
Active
Viewed 52 times
0

Sartheris Stormhammer
- 2,534
- 8
- 37
- 81
-
then again call that service in side of onLOwMemory() method...but you said that this method was not executing..so can you have a look on that once ? or else post that code .. – GvSharma Sep 12 '14 at 11:55
-
possible duplicate of [START\_STICKY does not work on Android KitKat (Edit: And Jelly Bean)?](http://stackoverflow.com/questions/20636330/start-sticky-does-not-work-on-android-kitkat-edit-and-jelly-bean) – marcinj Sep 12 '14 at 11:58
-
I know its not being called, because I have placed a Log.v(thing, thing) in that method, and its not shown after the timers in the service stop, after Android gets its memory full. And what code should I post? – Sartheris Stormhammer Sep 12 '14 at 11:59
1 Answers
1
I belive you have encountered problem that is issued as a bug here:
https://code.google.com/p/android/issues/detail?id=63793
but probably google finds it more like a feature.
If your service is supposed to run all the time then think about making it foreground service.

marcinj
- 48,511
- 9
- 79
- 100
-
the service I am using is supposed to run all the time, even when the app itself isnt running at all, but let me check the docs about Foreground Service – Sartheris Stormhammer Sep 12 '14 at 12:01
-
nope, foreground service doesnt seem good for me, I want the notifications for my app to be only those that are fired at the certain time periods – Sartheris Stormhammer Sep 12 '14 at 12:06
-
Then maybe AlarmManager with intentservice will suit your needs : https://github.com/commonsguy/cwac-wakeful. – marcinj Sep 12 '14 at 12:08
-
for recreating the service, or for all the notifications that need to be sent in the future? – Sartheris Stormhammer Sep 12 '14 at 12:17
-
For doing background work in time intervals. IntentServices are suited mostly for short tasks. If you want background service that will do continuous background work then you need to use foreground service with notification - thats because user should know your app is running. You might also look into writing your own account - but I have little experience with it (http://stackoverflow.com/questions/24227274/how-to-add-programmatically-a-custom-account-in-android). – marcinj Sep 12 '14 at 12:24