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. how to change location provider provider...

i have developed an app which just notify when location changed...
it used GPS_PROVIDERS as provider..
but as devices go inside of some building. it stop listening ..
i want to change the provider at that time to network provider..
so should i write locationManager.requestLocationUpdate method there in
status change method of listener.with provider to network provider...
or something else will do the task...

-- 

 A N K ! T......

-- 

2. Android Canvas.getMatrix followed by Canvas.setMatrix(null) raises NullPointerException

In the lunar lander example, if I add the following two lines to the
top of the doDraw method, the app crashes immediately with a
NullPointerException:

<pre>
Matrix m = canvas.getMatrix();
canvas.setMatrix( null );
</pre>

Stack trace is:
<pre>
FATAL EXCEPTION: Thread-8
java.lang.NullPointerException
    at android.graphics.Matrix.preConcat(Matrix.java:233)
    at android.view.Surface$CompatibleCanvas.setMatrix(Surface.java:
259)
    at com.example.android.lunarlander.LunarView
$LunarThread.doDraw(LunarView.java:617)
    at com.example.android.lunarlander.LunarView
$LunarThread.run(LunarView.java:360)
</pre>

The canvas documentation for setMatrix states that "If the matrix
parameter is null, then the current matrix is reset to identity", so
there's no reason this should crash.

Also, if I do not call getMatrix before calling setMatrix(null), then
setMatrix(null) is successful.  So it would seem that it is the
combination of the two calls that are causing a problem.

Whats going on here?

-- 

3. Problem in running test case

4. Help!!! Unknown Error - java.lang.NullPointerException :: Android Packaging Problem

5. SDK Add-on for Samsung Galaxy Tab

6. Galaxy Tab SDK missing shared library

7. Crash report: NoSuchFieldError