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. I formed preference using XML, but I don't know how can I open other view using XML tag intent...

Hi, all.

I formed preference view using XML codes..
in here, I wonder that how can I show other View at click this item
using <intent> tag.

if not available, could you give me some advice about this...
I want to implement using XML tag


<PreferenceScreen
     android:id="@+id/category_list_preference"
     android:title="@string/title_category_preference"
     android:summary="@string/explain_category_preference">

     <intent
            android:action="android.intent.action.VIEW"
            android:data="android.app.MoneyAgent" />
</PreferenceScreen>

--~--~---------~--~----~------------~-------~--~----~

2. Which process is responsible for injecting KeyEvents to the system ?

Hi all:
      This happened When i tryed to send keyevents repeatly: After a
period of time (may be 2h or more) , I started to get
RemoteExceptions. obviously, the process hadling keyevents is
dead ,But i'm not sure which process is,Could anyone tell me ?
     And, how i could avoid this happen ? Or,how could i recover the
system after this error(maybe just killing the Process is ok?)
    Thanks in advance !

Ashrotronics
--~--~---------~--~----~------------~-------~--~----~

3. migrating 1.5_pre -> 1.5_r1

4. Multiple shapes on one Drawable

5. Make an Alert for a background process

6. Initial database population from large data files, several problems

7. android startup problem after moving from SDK-1.0 to 1.5