Hi,
I am writing a service which shall continuously log some sensor data
over longer periods of time. For testing purposes the service shall
log a static debug message once every second. Looking at the log file,
after some time (usually 30min to several hours), the logging only
takes place every 10 minutes, every half an hour or sometimes even
only once an hour. When I connect the phone to my computer, the
service starts logging every second again.

There are already some posts dealing with the same problem, but I did
not find an appropriate answer. Maybe someone can help to clarify ?

Here are some details of the implementation:

The service is started once the device completed its boot process (or
once the corresponding activity is launched) using:

Intent serviceIntent = new Intent(getApplicationContext(),
TestService.class);
startService(serviceIntent);

The service itself overrides onStartCommand() with

public int onStartCommand(Intent intent, int flags, int startId)
{
        return START_STICKY;
}

so that the service shall be restarted if Android decides to stop it.
And in the onCreate method I start a periodic task to log:

Timer timer = new Timer();
timer.schedule(new TimerTask() {
        public void run()
        {
                writeToDebugFile("TestService: Control Message.",
getApplicationContext());
        }
}, 0, 1000);

As an alternative I tried to create my own logging-thread, but that
did not help either.
I also tried to let the service run in the foregound using

startForeground(334, myNotification);

without success.

I tested the implementation with an out-of-the-box Nexus Prime, with
no other apps installed or running.

Just in case someone wants to replay the problem, an eclipse export of
a minimal test case can be downloaded here:

http://www.hyfy.de/temp/ContinuousServiceTest.zip

Thanks for any comments !
Regards Dirk

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to