I need to review the code and think about this before asking any dumb questions. But one quick thought comes to mind.
Once I have a location, wouldn't getLastKnownLocation() return it to me? If so, the "60-second" service can see whether it gave me a location and use it. A second service can execute with much less frequency (every hour?) to update that location. In this scenario, the appwidget would start two services: sunrise and locationupdater. The Sunrise service is kicked every 60 seconds and gets the last known location. The locationupdater service runs every hour and gets a new location fix - which is picked up by the sunrise service the next time it runs. Does this make any sense? ...Jake >>>>> "MM" == Mark Murphy <[email protected]> writes: MM> On Fri, Feb 18, 2011 at 12:27 PM, Jake Colman <[email protected]> wrote: >> Lets say you have a widget that displays the number of minutes remaining >> until Sunrise. The widget itself cannot, in its own context, determine >> its location for astronomical calculations since that takes too long. >> So we use a service to do the actual work of figuring out where we are >> and what time is Sunrise. The widget sets up an alarm so that its >> broadcast receiver gets a notification every 60 seconds (or configurable >> time period) so as to start the service and update the widget. >> >> If I understand Mark's books and other sources correctly this should be >> the correct way to approach the problem - I hope! MM> The notion of using a service to figure out where we are and when MM> sunrise is seems reasonable. MM> I am not particularly a fan of updating an app widget every 60 MM> seconds, though the configurable time period is reasonable. >> So how do I now handle the location issue? getLastKnownLocation() won't >> work, as pointed out, since there may not be one. So do I have the >> service set up a location listener to et the initial update and then >> only take new updates when the location changes by X miles? Or is the >> service not the correct place to have the listener? MM> This is a complex problem. I took a stab at it with my LocationPoller: MM> https://github.com/commonsguy/cwac-locpoll MM> Basically, it is designed to be woken up by an AlarmManager alarm and MM> then figure out where you are, taking into account WakeLocks, the MM> delay in getting a location fix, and so on. I tested it with GPS, MM> though it should work with the network provider as well. MM> So, you would use an alarm with LocationPoller to figure out where you MM> are periodically, and tag along the logic to then compute sunrise. MM> Allow the user to configure how frequently you check your location, as MM> well as how frequently to update the app widget display (hint: MM> checking for locations every 60 seconds will *so* not be a good idea). MM> Note that LocationPoller is rather experimental code at this stage. MM> Your kilometerage may vary. MM> I thought that LocationPoller would not be needed with the MM> PendingIntent-based requestLocationUpdates(), but I had poor results MM> with that. >> At every service start the service needs to know where it is so that it >> can update the time to sunrise in case we moved. So maybe what I really >> need is a one-shot quick location fix for the current location and not a >> listener. I don't care to know where I am unless I am ready to update >> the widget. MM> You might not even be able to get a fix in 60 seconds (e.g., user is MM> in a spot with no signal). MM> -- MM> Mark Murphy (a Commons Guy) MM> http://commonsware.com | http://github.com/commonsguy MM> http://commonsware.com/blog | http://twitter.com/commonsguy MM> Android 2.3 Programming Books: http://commonsware.com/books MM> -- MM> You received this message because you are subscribed to the Google MM> Groups "Android Developers" group. MM> To post to this group, send email to [email protected] MM> To unsubscribe from this group, send email to MM> [email protected] MM> For more options, visit this group at MM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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

