Also if this app is doing something for the user that they care about, by
all means use startForeground(), have a notification to tell them it is
running, and give them a UI to decide whether or not it should run.  Then
they can make that decision.

On Thu, Jun 10, 2010 at 5:20 PM, Mark Murphy <mmur...@commonsware.com>wrote:

> Tejas wrote:
> > Now, my question is :  Will using the timer class, have the same effect
> > as using the AlarmManager ? or will it consume more resources.
>
> Generally speaking, your goal is to not have your code run and not have
> your code be in memory. The more your code runs, the more battery you
> consume. The more memory you take up, the more difficult it is for other
> applications to run. And, as Ms. Hackborn mentioned, your service will
> eventually be destroyed, anyway.
>
> The best way to do polling operations in Android is to use the
> AlarmManager and an IntentService. However, that does not work well with
> interfaces where you have to register listeners, such as SensorManager.
>
> Another way to do polling operations in Android is to use the
> AlarmManager and a regular service that does something like this:
>
> -- in onStart(), attaches itself to SensorManager and anything else
> listener-based
> -- as those listeners are called, collects data
> -- as soon as it gets data from all listeners and records it, the
> service calls stopSelf()
>
> So long as those listeners will do their work in a shorter time than
> your polling period, you should be fine.
>
> This keeps your code out of memory the vast majority of time.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android 2.2 Programming Books: http://commonsware.com/books
>
> --
> 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<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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