[android-developers] Continuously running Service does not run continuously
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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Continuously running Service does not run continuously
On Sat, Jan 14, 2012 at 12:43 PM, Dirk b...@informatik.uni-hamburg.de wrote: 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. That is because the phone is falling asleep. Users like it when their phone falls asleep, as this maximizes battery life. 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); You do not need getApplicationContext() here. Please replace it with the this object reference. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in NYC: http://marakana.com/training/android/ -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Continuously running service.
Hi, I would like to develop an application that will run continuously as a service in the background invisible to user. And after regular interval, it will send the location updates to the server. How can I make my application to run continuously in background invisible to user? Regards, Mahavir Jain -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en