Fix NPE when coming back to settings homepage.
When users navigate back to the homepage, if there is a slice being displayed, slice callback will be triggered. It will then check if this slice has any error hint, where NPE would occur if the slice turns out to be null. Hence, add a null check before checking slice hint. Fixes: 148158780 Test: rebuild and navigate back to the homepage. Change-Id: I2b04dc0d64a223cc85f6af55b2ae2dbc5f3e1f40
This commit is contained in:
@@ -120,6 +120,11 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life
|
||||
swipeBackground.setVisibility(View.GONE);
|
||||
}
|
||||
sliceLiveData.observe(mLifecycleOwner, slice -> {
|
||||
if (slice == null) {
|
||||
// The logic handling this case is in OnErrorListener. Adding this check is to
|
||||
// prevent from NPE when it calls .hasHint().
|
||||
return;
|
||||
}
|
||||
if (slice.hasHint(HINT_ERROR)) {
|
||||
Log.w(TAG, "Slice has HINT_ERROR, skipping rendering. uri=" + slice.getUri());
|
||||
mSliceLiveDataMap.get(slice.getUri()).removeObservers(mLifecycleOwner);
|
||||
|
Reference in New Issue
Block a user