From c463aee2b8c5e00397cb14e72dc9b2f33b1108b0 Mon Sep 17 00:00:00 2001 From: Shen Lin Date: Tue, 13 Sep 2022 16:26:17 +0800 Subject: [PATCH] Fix the IllegalArgumentException from RecyclerView Attempt to remove the animator as early as possible to avoid a RecyclerView crash. Bug: 246411107 Related bug: 184214085 Test: manual. Change-Id: I8fcb06836217f4de200a53bb88a1a0b5e42bbe21 --- .../settings/widget/HighlightablePreferenceGroupAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java index 9009b32be9e..9992ae71916 100644 --- a/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java +++ b/src/com/android/settings/widget/HighlightablePreferenceGroupAdapter.java @@ -148,11 +148,11 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter }, DELAY_COLLAPSE_DURATION_MILLIS); } + // Remove the animator as early as possible to avoid a RecyclerView crash. + recyclerView.setItemAnimator(null); // Scroll to correct position after 600 milliseconds. root.postDelayed(() -> { mHighlightRequested = true; - // Remove the animator to avoid a RecyclerView crash. - recyclerView.setItemAnimator(null); recyclerView.smoothScrollToPosition(position); mHighlightPosition = position; }, DELAY_HIGHLIGHT_DURATION_MILLIS);