SliceLiveData should remove observers.
As positions of items will be changed, new sliceViews will be created. SliceLiveData has been set to observe a certain old sliceView. When the page is re-launched, we cannot garantee we always get the same sliceView, which means the sliceLiveData may be still observing a sliveView that is no longer applicable. This will lead to broken slices. Hence, we need to remove observers first then make it observes a new sliceView. Bug: 117922624 Test: robotests, visual Change-Id: I59368a6ce5fa84487c9a4788b970fdc074a0c2a9
This commit is contained in:
@@ -91,14 +91,16 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer,
|
||||
if (sliceLiveData == null) {
|
||||
sliceLiveData = SliceLiveData.fromUri(mContext, uri);
|
||||
mSliceLiveDataMap.put(uri.toString(), sliceLiveData);
|
||||
sliceLiveData.observe(mLifecycleOwner, slice -> {
|
||||
if (slice == null) {
|
||||
Log.w(TAG, "Slice is null");
|
||||
}
|
||||
cardHolder.sliceView.setSlice(slice);
|
||||
});
|
||||
}
|
||||
|
||||
sliceLiveData.removeObservers(mLifecycleOwner);
|
||||
sliceLiveData.observe(mLifecycleOwner, slice -> {
|
||||
if (slice == null) {
|
||||
Log.w(TAG, "Slice is null");
|
||||
}
|
||||
cardHolder.sliceView.setSlice(slice);
|
||||
});
|
||||
|
||||
// Set this listener so we can log the interaction users make on the slice
|
||||
cardHolder.sliceView.setOnSliceActionListener(this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user