Mark:
I took some excerpts from your fabulous sample online. I have never worked
w/ a WakefulIntentService before and am finding it hard to follow.
What is calling the doWakefulWork(Intent) function?
The AlarmManager is set to fire OnAlarmReceiver and passes a special Intent
to it w/ an attached bundle. I need some info from that bundle, and
although the doWakefulWork() function takes an intent as an argument, that
Intent does not appear to be the one that has the Bundle that was originally
set.
So, I set the alarm in the BootReceiver like this:
----------------------------------------------------------------------------
----
Intent i = new Intent(context, OnAlarmReceiver.class);
Bundle b = new Bundle();
b.putLong("res_id", res_id);
i.putExtras(b);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
(int)res_id, i, 0);
AlarmManager alarmManager = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
(System.currentTimeMillis() + (5 * 1000)), (res_check_frequency * 60000),
pendingIntent);
----------------------------------------------------------------------------
----
And this is the OnAlarmReceiver class:
----------------------------------------------------------------------------
----public class OnAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
WakefulIntentService.acquireStaticLock(context);
context.startService(new Intent(context, AppService.class));
}
}
----------------------------------------------------------------------------
----
And in AppService:
----------------------------------------------------------------------------
---- public AppService() {
super("AppService");
}
@Override
protected void doWakefulWork(Intent intent) {
Log.d(TAG, "Fired alarm");
Bundle b = intent.getExtras();
if (b != null) {
long res_id = b.getLong("res_id");
Log.d(TAG, "Resource ID: " + Long.toString(res_id));
}
}
----------------------------------------------------------------------------
----
Using your example, how can I attach the Bundle received in OnAlarmReceiver
to the Intent sent as an argument in the doWakefulWork() function?
Thanks,
Nick Owens
VP, ThreeClix
Office: (904) 429-7039
Mobile: (847) 565-9392
After Hours: (904) 540-5830
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Mark Murphy
Sent: Saturday, February 27, 2010 6:02 PM
To: [email protected]
Subject: Re: [android-developers] AlarmManager Not Firing Receiver
Nick Owens wrote:
> I've got a registered BootReceiver for re-registering the repeating alarm.
> I know it fires on boot b/c the log message clearly shows it is firing and
> re-setting the repeating alarm in question for the same frequency.
>
> But the AlarmManager is not firing. Basically, the nearly identical code
> for setRepeating() fires when set from the app and continues to run when
the
> app is closed, so I know my AlarmReceiver is functioning, but the
> AlarmManager is either not broadcasting this alarm or my receiver doesn't
> work from an alarm set in the boot receiver. Below is the code for
setting
> the alarm from the BootReciver:
>
> --------------------------------------------------------------------------
>
> Intent i = new Intent(context, AlarmReceiver.class);
> Bundle b = new Bundle();
> b.putLong("res_id", res_id);
> i.putExtras(b);
>
> PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
> (int)res_id, i, 0);
>
> AlarmManager alarmManager = (AlarmManager)
> context.getSystemService(Context.ALARM_SERVICE);
> alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
> (System.currentTimeMillis() + (5 * 1000)), (5 * 60000), pendingIntent);
>
> --------------------------------------------------------------------------
>
> I read somewhere that the AlarmReceiver definition in the manifest needs
an
> intent-filter or 2 specified. I don't have any intent-filters, nor would
I
> know what to put in there. Is that perhaps why? I mean it could make
sense
> b/c the call to setRepeating from the activity w/in my app would still
work
> b/c the broadcast has more information about what receiver needs the
alarm,
> whereas when it's being set from the bootreceiver, the receiver in my
> manifest isn't defined well enough to get the broadcast? Here's my
manifest
> definition for the receiver:
>
> <receiver android:name=".AlarmReceiver" android:process=":remote" />
>
> At the following PDF (Page 25), it suggests a fully-qualified app name
> intent-filter:
>
>
http://docs.huihoo.com/google/io/2009/W_0300_CodingforLife-BatteryLifeThatIs
> .pdf
Try examining this:
http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices/Alarm/
which uses this:
http://github.com/commonsguy/cwac-wakeful
and see if that helps.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | 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
--
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