3

I have created a simple service and calling it from an activity with startService(intent). I am returning START_STICKY from my service's onStartCommand(). I want the service to keep running even if the activity is closed or removed from task list. When I test on emulator it is working fine - service is restarted after a second if I remove the application from recent screen list (by swiping or clear all). But on real device (running on Android 5.1) the service is killed but not started. I can see the following message.

04-22 20:26:26.436 714-1454/? W/ActivityManager: Scheduling restart of crashed service com.example.xxx.MyPkg/.MyService in 1000ms

04-22 20:26:26.441 714-1454/? I/ActivityManager: Force stopping service ServiceRecord{9df8b23 u0 com.example.xxx.MyPkg/.MyService}

Also, at some other point I have scheduled a start of the same service using Alarmmanager and PendingIntent. If the application is there in recent list, then only the service start works through Alarm, else not. Again, on emulator it is working fine.

I read fews questions and answers which says that START_STICKY has some issues in Kitkat and JellyBean. There were suggestions of scheduling a restart after few seconds from service's onTaskRemoved(). But firstly, I don't see onTaskRemoved() getting called on all clearing actions. And secondly, given that scheduled service start is not working when app is not present in task list, I am not sure it will work even if I schedule from onTaskRemoved() or activity's onDestroy().

Is there any way to get around this issue?

Supratim Haldar
  • 2,376
  • 3
  • 16
  • 26
  • After reading some more articles and answers, (and based on the above logcat message) what I understood is - the app is being "Force Killed" when I remove by swiping from recent app list or task manager. I scheduled an alarm with pending intent in activity's onDestroy() after 15 secs. But since the app is killed, the alarm is no longer there too. I checked this with sysdump alarm. Any workaround will be really helpful!! – Supratim Haldar Apr 29 '16 at 11:05
  • The same is happening here. Did you solve this problem? – Sandro Simas Jul 08 '16 at 05:16
  • Hi, no I could not find any resolution for this issue. In some phones (Nexus and few Samsung models), the service is restarting but in most models the app is kind of "force killed" when cleared from recent list. – Supratim Haldar Jul 08 '16 at 18:44
  • Here is a thread with this problem. Unfortunately, I still haven't solved it even based on the suggested solutions: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=53313 – user2924714 Jul 21 '16 at 14:58
  • Do you know what devices you were having this problem with? – David Wasser Aug 17 '17 at 14:59

0 Answers0