> i would like that when my app is closed it still run in the background
> (like at my tracks) to collect data even when it is closed.

Use a Service.

> but it always dies after a while by itself, why?

Android may have killed off your process to reclaim memory. And, of
course, if the device goes to sleep, your background thread will also go
to sleep, which may or may not be what you want.

Particularly for a polling-style application, use an AlarmManager to
arrange for a Service to do the work. That allows your whole application
to close down between polls, minimizing your memory and battery footprint.
I have a blog post briefly describing this technique:

http://androidguys.com/?p=4411

Also:

-- Do not busy-wait like you are in your code. You want your code to run
almost never.

-- Do not poll frequently.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to