A user selects alarm settings and then a intent is loaded with extras
and passed to start alarm ... which starts the pending intent

/* Starts alarm for one-time-occurrence system wide. Application must
start alarm again after occurrence. */
public static long startAlarm(Context context, Intent alarm, Class<?>
receiver) {

                long dateOccur = -1;

                // build pending intent
                alarm.setClass(context, receiver);
                PendingIntent alarmIntent = PendingIntent.getBroadcast(context,
API_ID+alarm.getIntExtra(ALARM_ID, -1), alarm,
PendingIntent.FLAG_CANCEL_CURRENT);

.... /// MORE STUFF
}

After the pending intent is receivedivity t I launch a new activity to
alert the users and give them a snooze/dismiss option.

BROADCAST RECEIVER CLASS
@Override
        public void onReceive(Context context, Intent intent) {

                // it is imperative to strip snooze
                if (intent.hasExtra(AlarmHandler.ALARM_SNOOZE)) {
                        //Log.d(MainActivity.DEBUG_ID, "This is a SNOOZE 
alarm.");
                        intent.removeExtra(AlarmHandler.ALARM_SNOOZE);
                }

                PowerManager pm = (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock wake
=pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "ConcProd");
                wake.acquire();
                AlarmActiveActivity.wake = wake;

                // launch notification activity
                intent.setClass(context, AlarmActiveActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
        }

Then from the alert activity that is fired I use the OnClick to set a
snooze option ... and call the startAlarm again using the orig intent
that was passed to it.

@Override
        public void onClick(View view) {

                // cancel sounds
                mNotification.cancelAll();

                //DISSMISS SNOOZE!
                // depending on action this is where we will reset the alarms
                if (view.getId() == R.id.btnSnooze) {
                        // snooze is a fun alarm set for 5 minutes away!
                        mAlarm.putExtra(AlarmHandler.ALARM_SNOOZE, true);
                        AlarmHandler.startAlarm(this, mAlarm, 
AlarmReceiver.class);

                }
                wake.release();
                finish();

        }

if the onclick wasn't fired it means that the alarm was simply
dismissed and I call startAlarm to start it again for the next day...

        @Override
        protected void onDestroy() {
                // we will assume dismiss if not snoozing so just reset
                if (!mAlarm.getBooleanExtra(AlarmHandler.ALARM_SNOOZE, false))
                        if (mAlarm.getBooleanExtra(AlarmHandler.ALARM_ENABLED, 
false)) {
                                AlarmHandler.startAlarm(this, mAlarm, 
AlarmReceiver.class);

                        }
                super.onDestroy();
        }

It is confusing and I'm not sure how to explain it ...
I observe that in only occurs after FLAG_NEW_ACTIVITY_FLAG has been
assigned to the original intent to fire the notification window?

No sure why it doesn't happen in SDK < 2.0


On Apr 30, 4:30 pm, Dianne Hackborn <[email protected]> wrote:
> It would be useful if you actually showed all of the relevant code.
>
> If you are making a broadcast pending intent, FLAG_ACTIVITY_NEW_TASK should
> appear in no place related to it, since that flag is for activities.
>
>
>
> On Fri, Apr 30, 2010 at 8:30 AM, cnich <[email protected]> wrote:
> > The actual intents being provided to the functions are flagged with
> > FLAG_ACTIVITY_NEW_TASK.
> > The intent is started and then passed to the code above.
> > When creating the pending intent with FLAG_CANCEL_CURRENT I receive
> > the error message Can't use FLAG_RECEIVER_BOOT_UPGRADE here.
>
> > This only occurs after the intent has been started.
>
> > On Apr 29, 9:58 pm, Dianne Hackborn <[email protected]> wrote:
> > > The Intent flags are supposed to be put on the Intent object (where they
> > are
> > > defined).  The flags when creating a pending intent are different.
>
> > > Also FLAG_RECEIVER_BOOT_UPGRADE is not for applications to use.  It is
> > not
> > > in the SDK.
>
> > > On Thu, Apr 29, 2010 at 4:03 PM, cnich <[email protected]> wrote:
> > > > Info on this error is elusive. It occurs in versions greater than 2.0.
>
> > > > I am firing a one time alarm using a Pending Intent. To create the
> > > > PendingIntent I pass an intent (alarm), context and, receiver class
> > > > into a function called startAlarm.
>
> > > > alarm.setClass(context, receiver);
> > > > PendingIntent alarmIntent = PendingIntent.getBroadcast(context, API_ID
> > > > +alarm.getIntExtra(ALARM_ID, -1), alarm,
> > > > PendingIntent.FLAG_CANCEL_CURRENT);
>
> > > > I can call the function without error before the alarm occurs ... but
> > > > after the PendingIntent has launched I receive
>
> > > > Can't use FLAG_RECEIVER_BOOT_UPGRADE here, when calling getBroadcast()
>
> > > > This occurs with all FLAGS except NO_CREATE.
>
> > > > What exactly is causing this error?
>
> > > > Thanks for any info.
>
> > > > -Cody
>
> > > > --
> > > > 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]<android-developers%[email protected]>
> > <android-developers%2bunsubs­[email protected]>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > [email protected]
>
> > > 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 [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-developers%[email protected]>
> > > For more options, visit this group athttp://
> > groups.google.com/group/android-developers?hl=en- Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> > 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]<android-developers%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://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

Reply via email to