What does the background service do, exactly?  Sorry, I don't really
want to sort through the two versions of your code.

What I did see in the alarm version leads me to suggest that you can
set a repeating alarm in your Activity after collecting the initial
data rather than set a new Alarm each time your broadcast receiver is
called.  If you describe what went wrong trying to use the alarm
manager maybe you can drop the excess baggage of a background
service.  Since you are trying to measure performance, you really
ought to go the extra mile to drop the extra process and be sure your
app does all it should to mitigate any performance impact.


On Sep 15, 5:02 am, Walles <[email protected]> wrote:
> Good point :-), here's the plan:
>
> I'm writing an app to find out what apps are using the most CPU time
> (which I hope will correlate with battery drain).  It's possible to
> get a snapshot picture of this by looking at 
> /proc:http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/annotate/head...
>
> A single snapshot picture will however miss apps that start, run for
> some time and then exit.
>
> So what I want to do is to take *regular* snapshots.  I take the
> difference between the last two snapshots and add the difference to a
> process name -> number of ticks Map.
>
> Snapshotting rules are:
> * Snapshots should be taken at regular intervals.
> * The first two snapshots should be taken in quick succession to be
> able to quickly present the first measurement to the user.
> * It must be possible for an UI app to look at the result of the
> snapshotting.
>
> To get the whole thing going, I'm letting the UI part of the
> application start the sampler in the background.  When the sampling is
> first started it needs to take two snapshots quickly (see above).  The
> rest of the samples should be taken at longer intervals.
>
> I first tried to do this using alarms, but I didn't manage to get the
> "two quick samples first and the rest further apart" behavior with
> alarms:http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/files/39
>
> I now have a working implementation with a background 
> service:http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/files/57
>
> Suggestions on how I should *really* be doing welcome :-).
>
>   Cheers //Johan
>
> On 9 Sep, 16:47, Mark Murphy <[email protected]> wrote:
>
> > Walleswrote:
> > > I'll use a Service instead of an Alarm and keep it running in the
> > > background.  That way I can keep track of it myself.
>
> > Please don't. For starters, it won't work, since the service may get
> > killed off by the user or the system. Also, while the service is in
> > memory, you are taking up one process' worth of RAM.
>
> > If you could explain to us what the effect is you are trying to achieve
> > (versus low-level technical statements, like "not to overwrite an
> > existing alarm with a new one"), we might be able to suggest alternative
> > patterns.
>
> > --
> > Mark Murphy (a Commons 
> > Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > _Android Programming Tutorials_ Version 1.0 In Print!
>
>
--~--~---------~--~----~------------~-------~--~----~
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