Try to search your question here, if you can't find : Ask Any Question Now ?

'Parcel: unable to marshal' with multiple pending intents

HomeCategory: stackoverflow'Parcel: unable to marshal' with multiple pending intents
Avatarrupesh asked 3 months ago

I am trying to create an alarm app that able to set multiple alarms, but I need to send a custom arraylist to onReceive, the problem is that it throws…

java.lang.RuntimeException: Parcel: unable to marshal value id:7, type:kitchen, wkt:LINESTRING (11.6999998092651 8.40000057220459, 11.4499998092651 9.85000038146973, 10.6500005722046 10, 8.5 9.19999980926514, 9.15000057220459 8.90000057220459, 10.9499998092651 9.25, 11.6999998092651 8.40000057220459), centerX:10.400001,centerY:9.266667, owner:null, keyword:Kitchen, subMap:0
    at android.os.Parcel.writeValue(Parcel.java:1418)
    at android.os.Parcel.writeList(Parcel.java:759)
    at android.os.Parcel.writeValue(Parcel.java:1365)
    at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
    at android.os.Bundle.writeToParcel(Bundle.java:1079)
    at android.os.Parcel.writeBundle(Parcel.java:711)
    at android.content.Intent.writeToParcel(Intent.java:7801)
    at android.os.Parcel.writeTypedArray(Parcel.java:1254)
    at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:4070)
    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:531)
    at android.app.PendingIntent.getBroadcast(PendingIntent.java:515)
    at com.asus.robot.onzenbo.dbAlarmManager.startAlarm(dbAlarmManager.java:327)
    at com.asus.robot.onzenbo.dbAlarmManager.onTimeSet(dbAlarmManager.java:315)
    at com.asus.robot.onzenbo.dbAlarmManager.TimeReceive(dbAlarmManager.java:170)
    at com.asus.robot.onzenbo.dbAlarmManager$2.onSuccess(dbAlarmManager.java:146)
    at com.asus.robot.onzenbo.dbAlarmManager$2.onSuccess(dbAlarmManager.java:129)
    at com.google.android.gms.tasks.zzn.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5444)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)

It seems that the problem is caused by pendingIntent.

private void  startAlarm(ArrayList<Long> aTime) {
    AlarmManager[] alarmManagers = new AlarmManager[20];
    ArrayList<PendingIntent> intentArrayList = new ArrayList<>();

    for (int i = 0 ; i<aTime.size(); i++)
    {
        Intent intent = new Intent(this, AlarmReceiver.class);
        intent.putExtra("LOC", arrayListRooms);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this,i,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManagers[i] = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManagers[i].set(AlarmManager.RTC_WAKEUP, aTime.get(i),pendingIntent);

        intentArrayList.add(pendingIntent);
    }

}

Here is the read parcel which are auto generated except the arrayListRooms, my custom arraylist that return from a method.

protected dbAlarmManager(Parcel in) {
    super(robotCallback,robotListenCallback);
    location = in.createStringArrayList();
    time = in.createStringArrayList();
    sTime = in.readString();
    sLoc = in.readString();
    sTitle = in.readString();
    sFirstRoom = in.readString();
    sSecondRoom = in.readString();
    aTitle = in.createStringArrayList();
    intent = in.readParcelable(Intent.class.getClassLoader());
    hour = in.createIntArray();
    min = in.createIntArray();
    arrayListRooms =  in.createTypedArrayList((Creator<RoomInfo>) arrayListRooms);
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeStringList(location);
    dest.writeStringList(time);
    dest.writeString(sTime);
    dest.writeString(sLoc);
    dest.writeString(sTitle);
    dest.writeString(sFirstRoom);
    dest.writeString(sSecondRoom);
    dest.writeStringList(aTitle);
    dest.writeParcelable(intent, flags);
    dest.writeIntArray(hour);
    dest.writeIntArray(min);
    dest.writeList(arrayListRooms);

}

I also already has getters and setters for all parcel variables.

What should I do?
Thanks in advance.`

1 Answers
Best Answer
AvatarArben answered 3 months ago
Your Answer

13 + 3 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com