Hello,

I am having a few problems with my alarm code.

1. Suppose I set the alarm for the first time for it to expire at a future
time.
    In this case it goes off immediately instead of after the delay.

2. Every other time following the first time I set the alarm again for it to
expire at some future time
    it again goes off immediately, but this time displaying the data in the
parcel I passed to it the first time.

In fact I also get the following error in the adb LogCat messages. Even if I
run the application or reinstall it
from Eclipse I still get the same problem described above in (2).

E/Parcel  (   61): Class not found when unmarshalling:
com.foobar.foo.AlarmMessage, e: java.lang.ClassNotFoundException:
com.foobar.foo.AlarmMessage

W/Intent  (   61): Failure filling in extras

W/Intent  (   61): android.os.BadParcelableException: ClassNotFoundException
when unmarshalling: com.foobar.foo AlarmMessage

W/Intent  (   61):     at android.os.Parcel.readParcelable(Parcel.java:1958)

W/Intent  (   61):     at android.os.Parcel.readValue(Parcel.java:1846)

W/Intent  (   61):     at
android.os.Parcel.readListInternal(Parcel.java:2092)

W/Intent  (   61):     at android.os.Parcel.readArrayList(Parcel.java:1536)

W/Intent  (   61):     at android.os.Parcel.readValue(Parcel.java:1867)

W/Intent  (   61):     at
android.os.Parcel.readMapInternal(Parcel.java:2083)

W/Intent  (   61):     at android.os.Bundle.unparcel(Bundle.java:208)

W/Intent  (   61):     at android.os.Bundle.putAll(Bundle.java:281)

W/Intent  (   61):     at android.content.Intent.fillIn(Intent.java:5054)

W/Intent  (   61):     at
com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:195)

W/Intent  (   61):     at
com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:177)

W/Intent  (   61):     at
android.app.PendingIntent.send(PendingIntent.java:400)

W/Intent  (   61):     at
com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:685)

Here is my code:

----------------------------------- this is the parcel I am passing to the
broadcast receiver: -----------------------------------------------

class AlarmMessage implements Parcelable {

  public AlarmMessage(String groupName, Uri alarm, String nextAlarmDateTime,
String globalNote, String localNote) {

    this.groupName = groupName;
    this.alarm = alarm;
    this.nextAlarmDateTime = nextAlarmDateTime;
    this.globalNote = globalNote;
    this.localNote = localNote;

  }

  public int describeContents() {

    return 0;

  }

  public void writeToParcel(Parcel out, int flags) {

    out.writeString(groupName);
    out.writeString(alarm.toString());
    out.writeString(nextAlarmDateTime);
    out.writeString(globalNote);
    out.writeString(localNote);

  }

  public static final Parcelable.Creator<AlarmMessage> CREATOR = new
Parcelable.Creator<AlarmMessage>() {

    public AlarmMessage createFromParcel(Parcel in) {

      return new AlarmMessage(in);

    }

    public AlarmMessage[] newArray(int size) {

      return new AlarmMessage[size];

    }

  };

  private AlarmMessage(Parcel in) {

    groupName = in.readString();
    alarm = Uri.parse(in.readString());
    nextAlarmDateTime = in.readString();
    globalNote = in.readString();
    localNote = in.readString();

  }

  public String groupName;
  public Uri alarm;
  public String nextAlarmDateTime;
  public String globalNote;
  public String localNote;

}

------------------------------ here is the broadcast receiver that receives
the marshalled message as an intent parcel ----------------


package com.foobar.foo;

import java.util.ArrayList;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class AlarmReceiver extends BroadcastReceiver {

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

    Log.d("AlarmReceiver", "received");

    Intent i = new Intent(context, AlarmExpiredActivity.class);
    i.putParcelableArrayListExtra("alarmMessages",
intent.getParcelableArrayListExtra("alarmMessages"));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);

    ArrayList<AlarmMessage> alarmMessages =
intent.getParcelableArrayListExtra("alarmMessages");
    System.out.println(alarmMessages.get(0));

  }

}

-------------------------- and here is how I am setting/resetting the alarm
------------------------------------------------------------------


      Intent intent = new Intent(ctx, AlarmReceiver.class);
      intent.putParcelableArrayListExtra("alarmMessages", alarmMessages);
      pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent, 0);
      alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);

------------------------------------------------------------------------------------------------------------------------------------------------

My calendar object is set correctly as I checked this.

I don't see where the problem is with my code. I am hoping that someone here
can shed some light on this issue.

Regards,

John Goche

-- 
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