Intent.getIntExtra doesn't find value

by kaloer » Sun, 15 Nov 2009 05:39:47 GMT


Sponsored Links
 Hi,

I'm modifying the default Alarm Clock application source, but I have a
problem sending an Integer value with an Intent. This is where I put
the "snooze_duration" value into the Intent:

        static void enableAlert(Context context, int id, String label,
                        long atTimeInMillis, int dismissBehaviour, int 
snoozeBehaviour, int
snoozeDuration) {
                AlarmManager am = (AlarmManager) context
                                .getSystemService(Context.ALARM_SERVICE);

                Intent intent = new Intent(ALARM_ALERT_ACTION);
                if (Log.LOGV)
                        Log.v("** setAlert id " + id + " atTime " + 
atTimeInMillis);
                intent.putExtra(Alarms.ID, id);
                intent.putExtra(Alarms.LABEL, label);
                intent.putExtra(Alarms.TIME, atTimeInMillis);
                intent.putExtra(Alarms.DISMISS_BEHAVIOUR, dismissBehaviour);
                intent.putExtra(Alarms.SNOOZE_BEHAVIOUR, snoozeBehaviour);
                //HERE:
                intent.putExtra(Alarms.SNOOZE_DURATION, snoozeDuration);
                PendingIntent sender = PendingIntent.getBroadcast(context, 0,
intent,
                                PendingIntent.FLAG_CANCEL_CURRENT);

                if (true) {
                        am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);
                } else {
                        // a five-second alarm, for testing
                        am.set(AlarmManager.RTC_WAKEUP, 
System.currentTimeMillis() + 5000,
                                        sender);
                }

                setStatusBarIcon(context, true);

                Calendar c = Calendar.getInstance();
                c.setTime(new java.util.Date(atTimeInMillis));
                String timeString = formatDayAndTime(context, c);
                saveNextAlarm(context, timeString);
        }

But when I try reading it, it sets the defaultValue instead. The other
values works as they should, but the snooze_duration doesn't. I get
the values in the OnCreate() method in the activity started by the
Intent:

        Intent i = getIntent();
        mAlarmId = i.getIntExtra(Alarms.ID, -1);
        mDismissBehaviour = i.getIntExtra(Alarms.DISMISS_BEHAVIOUR,
0);
        mSnoozeBehaviour = i.getIntExtra(Alarms.SNOOZE_BEHAVIOUR, 0);
        mSnoozeDuration = i.getIntExtra(Alarms.SNOOZE_DURATION, 10);

Why doesn't this work? I have tried debugging, and it does put the
correct integer value in the Intent.putExtra method.

Thank you very much!

//Kaloer

--



Other Threads

1. Question about background task applications?

Is it possible to developp an application which :
- run in background (I know that it's possible with Services)
- is impossible to close or to stop ?

Best Regards
Tom

2. Google Map retains the reference to the context of the enclosing activity?

Still no luck. Seems I should report it as a bug...



> Katsiaryna

3. Bitmap formats

4. Nexus GPS antenna is always active when "Use GPS Satellites" is checked...

5. Forcing a mobile data connection

6. Nokia launches Ovi maps

7. Market access on the emulator?