Skip to content

Commit a89e38c

Browse files
pubiqqdsn5ft
authored andcommitted
[BottomSheet] Recycle the TypedArray after usage
Resolves #4032 GIT_ORIGIN_REV_ID=f9ac4cf68c6ef7cd41d0bbdca2c7d09b0f99f5d9 PiperOrigin-RevId: 633632973
1 parent 9b6ceac commit a89e38c

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

lib/java/com/google/android/material/bottomsheet/BottomSheetDialog.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,38 +90,33 @@ public class BottomSheetDialog extends AppCompatDialog {
9090

9191
public BottomSheetDialog(@NonNull Context context) {
9292
this(context, 0);
93-
94-
edgeToEdgeEnabled =
95-
getContext()
96-
.getTheme()
97-
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
98-
.getBoolean(0, false);
93+
initialize();
9994
}
10095

10196
public BottomSheetDialog(@NonNull Context context, @StyleRes int theme) {
10297
super(context, getThemeResId(context, theme));
10398
// We hide the title bar for any style configuration. Otherwise, there will be a gap
10499
// above the bottom sheet when it is expanded.
105100
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
106-
107-
edgeToEdgeEnabled =
108-
getContext()
109-
.getTheme()
110-
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
111-
.getBoolean(0, false);
101+
initialize();
112102
}
113103

114104
protected BottomSheetDialog(
115105
@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
116106
super(context, cancelable, cancelListener);
117107
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
118108
this.cancelable = cancelable;
109+
initialize();
110+
}
111+
112+
private void initialize() {
113+
final TypedArray a = getContext()
114+
.getTheme()
115+
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge});
116+
117+
edgeToEdgeEnabled = a.getBoolean(0, false);
119118

120-
edgeToEdgeEnabled =
121-
getContext()
122-
.getTheme()
123-
.obtainStyledAttributes(new int[] {R.attr.enableEdgeToEdge})
124-
.getBoolean(0, false);
119+
a.recycle();
125120
}
126121

127122
@Override

0 commit comments

Comments
 (0)