My background service is constantly getting killed only in specific devices like Lenovo vibe k5 (Already disabled Background App Management App). I've already tried checking if the service is running using Alarm Manager and GCM Periodic Task service but even these does not work when the app is killed but apps like Facebook and Gmail does get notifications. So I want to implement periodic sync using sync adapter to check if the service is running but couldn't find any proper documentation to get that to work. Can anyone provide me a reference on how to implement this?
Asked
Active
Viewed 225 times
2
-
First of all, did you try to return START_STICKY or START_REDELIVER_INTENT? See http://stackoverflow.com/questions/22058682/difference-between-start-sticky-and-start-redeliver-intent – Goltsev Eugene Oct 07 '16 at 13:07
-
Yes I did. I'm using START_STICKY. – Aman Kaushik Oct 07 '16 at 13:09
-
When the app is killed, even onDestroy() and onTaskRemoved are not called. – Aman Kaushik Oct 07 '16 at 13:13
-
@AmanKaushik see this answer may help you http://stackoverflow.com/a/35654729/4146722 – Pratik Tank Oct 07 '16 at 13:18
-
Also, u can try to use AlarmManager https://developer.android.com/reference/android/app/AlarmManager.html – Goltsev Eugene Oct 07 '16 at 13:25
-
Btw, if that phone has some native energy saver - it can kill your service, u can try to disable it. – Goltsev Eugene Oct 07 '16 at 13:25
-
1@GoltsevEugene Power saver is already disabled and Alarm Manager is also not working. And it is only happening in specific devices. In Xiaomi devices this problem goes away if the auto start has been turned on in Security but no solution for lenovo so far. – Aman Kaushik Oct 07 '16 at 13:36
-
can you show us your service? – user1506104 Oct 17 '16 at 04:23
-
@AmanKaushik Were you able to solve this issue? – Shyamal Parikh Jan 03 '17 at 19:09
-
@ShyamalParikh Yes but not with SyncAdapter. – Aman Kaushik Jan 04 '17 at 06:54