Я пытаюсь передать «Установить» значения из основного действия в фоновый сервис, запущенный в другом процессе (и наоборот). Поскольку я не нашел никакого метода «Bundle» или «Message.Obj», обрабатывающего «Sets», я конвертирую «Set» в «ArrayList». Отправка сообщения с этим источником «ArrayList» происходит без ошибок, так как служба получает сообщение. Однако, когда я пытаюсь получить «ArrayList» из «Сообщения», возникает ошибка.Как передать ArrayList из основного действия в фоновый сервис, работающий в отдельном процессе?
Вот исходный код "Parcelable" класса:
public class SavedCell implements Parcelable {
public String cssId;
public boolean isFinalized;
public boolean isInduced;
public Set<Integer> potential;
public SavedCell(Cell c) {
this.cssId = c.cssId;
this.isFinalized = c.isFinalized;
this.isInduced = c.isInduced;
this.potential = new HashSet(c.potential);
}
public SavedCell(String id, boolean f, boolean i, Set<Integer> p) {
this.cssId = id;
this.isFinalized = f;
this.isInduced = i;
this.potential = new HashSet(p);
}
public SavedCell(Parcel p) {
this.cssId = p.readString();
this.isFinalized = (p.readByte() != 0);
this.isInduced = (p.readByte() != 0);
int[] potentialArray = p.createIntArray();
this.potential = new HashSet();
for (int i : potentialArray) {
this.potential.add(i);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.cssId);
dest.writeByte((byte) (this.isFinalized ? 1 : 0));
dest.writeByte((byte) (this.isInduced ? 1 : 0));
int[] potentialArray = new int[this.potential.size()];
int idx = 0;
for (Iterator it=this.potential.iterator(); it.hasNext();) {
potentialArray[idx++] = (int) it.next();
}
dest.writeIntArray(potentialArray);
}
public static final Creator<SavedCell> CREATOR = new Creator<SavedCell>() {
@Override
public SavedCell createFromParcel(Parcel in) {
return new SavedCell(in);
}
@Override
public SavedCell[] newArray(int size) {
return new SavedCell[size];
}
};
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SavedCell other = (SavedCell) obj;
return this.cssId.equalsIgnoreCase(other.cssId);
}
}
Вот обработки отправки данных в основной деятельности код:
public void createInitialSnapshot(Set<SavedCell> sgc, boolean initialisePuzzle) {
ArrayList<SavedCell> bundledPuzzle = new ArrayList<>(sgc);
if (isSolveServiceBound) {
try {
Bundle b = new Bundle();
b.putParcelableArrayList("bundledPuzzle", bundledPuzzle);
Message msg = Message.obtain(null, MSG_SAVE_INITIAL_SNAPSHOT, (initialisePuzzle) ? 1 : 0, 0, null);
msg.setData(b);
msg.replyTo = messengerSolveClient;
messengerSolveService.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
И, наконец, код пытается получить данные в фоновом сервисе:
private void saveInitialSnapShot(Message msg) {
Bundle b = msg.getData();
if (b == null) {
...
} else {
...
ArrayList<SavedCell> bundledPuzzle = b.getParcelableArrayList("bundledPuzzle");
Set<SavedCell> sgc = new HashSet(bundledPuzzle);
...
}
При окружении «ArrayList bundledPuzzle = b.getParcelableArrayList (« bundledPuzzle »); в блоке try-catch сообщение об исключении: «android.os.BadParcelableException: ClassNotFoundException при unmarshalling: be.ema.sc.SavedCell».
**, когда я пытаюсь извлечь «ArrayList» из «Послания», возникает ошибка **, которая произошла ошибка? –