On Sat, Jul 16, 2011 at 12:04 PM, cathal coffey <[email protected]> wrote:
> Unless I am thinking about this incorrectly. The function onReceive
> in the OnAlarmReceiver class needs to have a reference to the widget
> instance, see the below code.
There is no "widget instance".
> How else can the OnReceive function know
> how many times it has fired and change its firing rate accordingly?
Use a file. Or a database. Or, conceivably, extras on the Intent you
use with the alarm. The first two would be simpler to code but will
involve disk I/O, which ideally is not performed on the main
application thread (where onReceive() and onUpdate() and such are
called).
> public class OnAlarmReceiver extends BroadcastReceiver
> {
> @Override
> public void onReceive(Context context, Intent intent)
> {
> MyWidget myWidget = SomeMagicFunction();
If "MyWidget" is a subclass of AppWidgetProvider, there is no instance
when your alarm goes off. An instance of MyWidget will hopefully live
for less than a millisecond, during your onUpdate() processing (and
any other app widget lifecycle methods you elect to respond to). Once
onUpdate() returns, that MyWidget instance is gone, until the next
onUpdate() call when a new instance is created.
Any data that you have that is supposed to persist beyond a single
onUpdate() call must live someplace else, such as a file, database,
etc.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
Warescription: Three Android Books, Plus Updates, One Low Price!
--
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