问题描述:
与同事联调数据,发送广播广播后,对方收到广播数据不存在我发的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;
}
}