有人可以向我解释一下吗?这是我的代码,之后,我将显示日志。事实是我有一个对象列表。我记录它的大小:1。我清除它,变成 0。我在其中添加对象,它仍然是 0。
这是我的代码:
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE" + index);
RealmList<TripStep> tripsteps = psTrip.getTripSteps();
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE2:" + psTrip.getTripSteps().size());
realmActive.beginTransaction();
TripStep tripStep = realmActive.copyToRealmOrUpdate(updateStepResponse.getStep());
realmActive.commitTransaction();
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE3 + index is:" + index);
realmActive.beginTransaction();
tripsteps.set(index, tripStep);
realmActive.commitTransaction();
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE4");
if (isRoaming) {
if ((tripsteps.size() - 2 == index) && !Utils.hasStarted(PSNewJourneyActivity.this)) {
realmActive.beginTransaction();
tripsteps.get(tripsteps.size() - 1).setTravelMode(updateStepResponse.getStep().getTravelMode());
realmActive.commitTransaction();
}
}
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip:" + tripSteps.size());
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip before:" + psTrip.getTripSteps().size());
realmActive.beginTransaction();
psTrip.getTripSteps().clear();
realmActive.commitTransaction();
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip AFTER CLEAR:" + psTrip.getTripSteps().size());
realmActive.beginTransaction();
for (TripStep tripStep1 : tripsteps){
psTrip.getTripSteps().add(tripStep1);
}
realmActive.commitTransaction();
realmActive.beginTransaction();
realmActive.copyToRealmOrUpdate(psTrip);
realmActive.commitTransaction();
Log.i("", "update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE6 tripstep size:" + psTrip.getTripSteps().size());
Handler han = new Handler();
han.postDelayed(new Runnable() {
@Override
public void run() {
continueInit(true, true);
ProgressForMap(true);
}
}, mapDelay);
这是我的日志:
update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE0
09-09 10:12:11.219 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE2:1
09-09 10:12:11.251 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE3 + index is:0
09-09 10:12:11.257 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE4
09-09 10:12:11.257 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip:1
09-09 10:12:11.257 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip before:1
09-09 10:12:11.264 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE5 tripsteps not in pstrip AFTER CLEAR:0
09-09 10:12:11.277 32740-32740/nl.hgrams.passenger I/﹕ update step pitstop 1 BEFORE TEST FOR ACTIVE -> ACTIVE6 tripstep size:0