Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-Service killed with "no longer want" - how to restart it?

Tags:

We have a Service that continuously collects sensor data on the phone. This service should run "forever", e.g. as long as the user wants, and not be killed by the system.

For clarification, this service is not intended for an app to be released in the market to the general public, it is written for a scientific study. So the people running the app are fully aware that their battery will sucked empty faster than usual, this is no problem.

Anyways, my problem is that the service gets killed after a while of running. Sometimes after an hour, sometimes only after like 7 oder 10 hours.

The Log-Entries when the service gets killed look like this. It just says "no longer want", sometimes without even calling onDestroy(), as far as I can tell.

07-20 17:07:11.593 I/ActivityManager(   85): No longer want my.project.datalogging (pid 23918): hidden #16 07-20 17:07:11.593 I/WindowManager(   85): WIN DEATH: Window{44c61570 my.project.datalogging/my.project.datalogging.DataLoggingApp paused=false} 07-20 17:07:11.603 I/BackgroundService(23925): onDestroy() 

Or later (after I manually restarted it):

07-20 19:00:49.677 I/ActivityManager(   85): No longer want my.project.datalogging:BackgroundService (pid 24421): hidden #17 07-20 19:00:49.677 I/ActivityManager(   85): No longer want my.project.datalogging (pid 24415): hidden #18 07-20 19:00:49.807    85 10707 I WindowManager: WIN DEATH: Window{44f1ea58 my.project.datalogging/my.project.datalogging.DataLoggingApp paused=false} 

I often see other services being killed with "no longer want" and then immediately restarted with "Scheduling restart of crashed service". For example here with runkeeper:

07-20 17:30:45.503 I/ActivityManager(   85): No longer want com.fitnesskeeper.runkeeper (pid 24090): hidden #16 07-20 17:30:45.603 W/ActivityManager(   85): Scheduling restart of crashed service com.fitnesskeeper.runkeeper/.services.RunKeeperService in 5000ms 07-20 17:33:52.989 I/ActivityManager(   85): Start proc com.fitnesskeeper.runkeeper for service com.fitnesskeeper.runkeeper/.services.RunKeeperService: pid=24292 uid=10099 gids={3003, 1015} 

The logs show no record of low memory. Testing is done on (several) Nexus One with 2.2 (Froyo FRF91).

Is there any way I can achieve this behaviour with my app? Automatic restarting after being killed?

Or this this something totally different that just looks similar in logcat?

If you need any more information, just ask and I'll try to provide it :-)

like image 440
pableu Avatar asked Jul 21 '10 07:07

pableu


1 Answers

How do you start the service? Have you tried startForeground()? That's not an absolute guarantee, of course, but should at least lengthen the lifespan.

like image 108
Pontus Gagge Avatar answered Oct 17 '22 15:10

Pontus Gagge