android跨进程发送广播,从Intent获取到的bundle数据key为null,同时程序报出ava.lang.RuntimeException: here

问题描述:

与同事联调数据,发送广播广播后,对方收到广播数据不存在我发的key
在反复确认双方的KEY使用字段完全一样不存在KEY写错的问题,同事也会报出下面的以上

 New hash 0 is before end of array hash 709763842 at index 2 key null
11-16 18:28:48.919 W/ArrayMap( 2100): java.lang.RuntimeException: here
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.util.ArrayMap.append(ArrayMap.java:607)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.Parcel.readArrayMapInternal(Parcel.java:3248)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.BaseBundle.unparcel(BaseBundle.java:236)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.BaseBundle.keySet(BaseBundle.java:562)
11-16 18:28:48.919 W/ArrayMap( 2100):   at com.pzdf.court.courtblendproduct.service.MyService$4.onReceive(MyService.java:121)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1550)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.Handler.handleCallback(Handler.java:883)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.Handler.dispatchMessage(Handler.java:100)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.os.Looper.loop(Looper.java:214)
11-16 18:28:48.919 W/ArrayMap( 2100):   at android.app.ActivityThread.main(ActivityThread.java:7356)
11-16 18:28:48.919 W/ArrayMap( 2100):   at java.lang.reflect.Method.invoke(Native Method)
11-16 18:28:48.919 W/ArrayMap( 2100):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
11-16 18:28:48.919 W/ArrayMap( 2100):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

于是我再新建个程序,与同事的程序接收的值进行打印
打印结果如下

我发送的打印
sendResult saveEvidenceActionType=2,saveEvidenceUserResult=-1,saveEvidenceUserObject=com.android.pzPhone.entity.SaveEvidenceEntity@696d3d7
我接收的打印
receiver action=com.android.pzPhone.action.sendEvidenceInformation,bundleBundle{ saveEvidenceUserObject => com.android.pzPhone.entity.SaveEvidenceEntity@6acb898; saveEvidenceUserResult => -1; saveEvidenceActionType => 2; }Bundle
同时程序的打印
receiver action=com.android.pzPhone.action.sendEvidenceInformation,bundleBundle{ null => null; saveEvidenceUserObject => SaveEvidenceEntity{callState=8, name='华子韶(被告)', callid='-1', isRecord=false, recordTime=0, callTime=0, number='13986052491'}; 2023-11-16 18:28:38 => {-1=false, 0=false, 1=false, 6357107=false, 6488129=false, 6553705=false, 6619235=false, 6619248=false, 6619254=false, 7209061=false, 7209071=false, 7471205=false, 7667827=false, 7733317=false}; }Bundle

从打印的结果上看,发现同事程序接收的intent中不存在我发的key,只有被序列化的对象打印结果正常,我自己的程序收到的值与发送的值一致

问题解决

最后把同事的代码拿过来进行联调发现
把广播中的SaveEvidenceEntity对象去掉,对方可以正常接收到值
于是对比双方的SaveEvidenceEntity对象
发现我的对象中多出了callStartTime字段,让对方程序把这个字段加上,程序intent传值正常

同事的对象代码

package com.android.pzPhone.entity;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class SaveEvidenceEntity implements Parcelable {
    int callState;
    String name;
    String callid;
    boolean isRecord;
    int recordTime;
    int callTime;
    String number;
    String recrodName;

    public String getRecrodName() {
        return recrodName;
    }

    public void setRecrodName(String recrodName) {
        this.recrodName = recrodName;
    }

    public int getCallState() {
        return callState;
    }

    public void setCallState(int callState) {
        this.callState = callState;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCallid() {
        return callid;
    }

    public void setCallid(String callid) {
        this.callid = callid;
    }

    public boolean isRecord() {
        return isRecord;
    }

    public void setRecord(boolean record) {
        isRecord = record;
    }

    public int getRecordTime() {
        return recordTime;
    }

    public void setRecordTime(int recordTime) {
        this.recordTime = recordTime;
    }

    public int getCallTime() {
        return callTime;
    }

    public void setCallTime(int callTime) {
        this.callTime = callTime;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }


    public SaveEvidenceEntity(int callState, String name, String callid, boolean isRecord, int recordTime, int callTime, String number, String recrodName) {
        this.callState = callState;
        this.name = name;
        this.callid = callid;
        this.isRecord = isRecord;
        this.recordTime = recordTime;
        this.callTime = callTime;
        this.number = number;
        this.recrodName = recrodName;
    }

    public SaveEvidenceEntity() {
        super();
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        return super.equals(obj);
    }

    @NonNull
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }

    protected SaveEvidenceEntity(Parcel in) {
        callState = in.readInt();
        name = in.readString();
        callid = in.readString();
        isRecord = in.readByte() != 0;
        recordTime = in.readInt();
        callTime = in.readInt();
        number = in.readString();
        recrodName = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(callState);
        dest.writeString(name);
        dest.writeString(callid);
        dest.writeByte((byte) (isRecord ? 1 : 0));
        dest.writeInt(recordTime);
        dest.writeInt(callTime);
        dest.writeString(number);
        dest.writeString(recrodName);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<SaveEvidenceEntity> CREATOR = new Creator<SaveEvidenceEntity>() {
        @Override
        public SaveEvidenceEntity createFromParcel(Parcel in) {
            return new SaveEvidenceEntity(in);
        }

        @Override
        public SaveEvidenceEntity[] newArray(int size) {
            return new SaveEvidenceEntity[size];
        }
    };

    @Override
    public String toString() {
        if(this==null){
            return "";
        }
        return "SaveEvidenceEntity{" +
                "callState=" + callState +
                ", name='" + name + '\'' +
                ", callid='" + callid + '\'' +
                ", isRecord=" + isRecord +
                ", recordTime=" + recordTime +
                ", callTime=" + callTime +
                ", number='" + number + '\'' +
                '}';
    }
}

我的对象代码

package com.android.pzPhone.entity;

import android.os.Parcel;
import android.os.Parcelable;

public class SaveEvidenceEntity implements Parcelable {
    int callState;
    String name;
    String callid;
    boolean isRecord;
    int recordTime;
    int callTime;
    String number;
    String recrodName;
    String callStartTime;

    public SaveEvidenceEntity(int callState, String name, String callid, boolean isRecord, int recordTime, int callTime, String number, String recrodName, String callStartTime) {
        this.callState = callState;
        this.name = name;
        this.callid = callid;
        this.isRecord = isRecord;
        this.recordTime = recordTime;
        this.callTime = callTime;
        this.number = number;
        this.recrodName = recrodName;
        this.callStartTime = callStartTime;
    }

    protected SaveEvidenceEntity(Parcel in) {
        callState = in.readInt();
        name = in.readString();
        callid = in.readString();
        isRecord = in.readByte() != 0;
        recordTime = in.readInt();
        callTime = in.readInt();
        number = in.readString();
        recrodName = in.readString();
        callStartTime = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(callState);
        dest.writeString(name);
        dest.writeString(callid);
        dest.writeByte((byte) (isRecord ? 1 : 0));
        dest.writeInt(recordTime);
        dest.writeInt(callTime);
        dest.writeString(number);
        dest.writeString(recrodName);
        dest.writeString(callStartTime);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<SaveEvidenceEntity> CREATOR = new Creator<SaveEvidenceEntity>() {
        @Override
        public SaveEvidenceEntity createFromParcel(Parcel in) {
            return new SaveEvidenceEntity(in);
        }

        @Override
        public SaveEvidenceEntity[] newArray(int size) {
            return new SaveEvidenceEntity[size];
        }
    };

    public int getCallState() {
        return callState;
    }

    public void setCallState(int callState) {
        this.callState = callState;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCallid() {
        return callid;
    }

    public void setCallid(String callid) {
        this.callid = callid;
    }

    public boolean isRecord() {
        return isRecord;
    }

    public void setRecord(boolean record) {
        isRecord = record;
    }

    public int getRecordTime() {
        return recordTime;
    }

    public void setRecordTime(int recordTime) {
        this.recordTime = recordTime;
    }

    public int getCallTime() {
        return callTime;
    }

    public void setCallTime(int callTime) {
        this.callTime = callTime;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getRecrodName() {
        return recrodName;
    }

    public void setRecrodName(String recrodName) {
        this.recrodName = recrodName;
    }

    public String getCallStartTime() {
        return callStartTime;
    }

    public void setCallStartTime(String callStartTime) {
        this.callStartTime = callStartTime;
    }
}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353

推荐阅读更多精彩内容