Fixing memory leak in PreferenceScreen.
Every time the PreferenceScreen is displayed a new ListView is created and bound to the adapter. As the same adapter is used during the lifetime of PreferenceScreen and the listviews never gets unbound, the adapter will contain a list of unused views. The old view should be unbound from adapter when we create a new view. Change-Id: I13e2d0dc79c8ff79b58efa650653e3f84c6e53c5
This commit is contained in:
committed by
Johan Redestig
parent
7d234fabe6
commit
190acd4dd0
@@ -80,6 +80,8 @@ public final class PreferenceScreen extends PreferenceGroup implements AdapterVi
|
||||
private ListAdapter mRootAdapter;
|
||||
|
||||
private Dialog mDialog;
|
||||
|
||||
private ListView mListView;
|
||||
|
||||
/**
|
||||
* Do NOT use this constructor, use {@link PreferenceManager#createPreferenceScreen(Context)}.
|
||||
@@ -145,15 +147,18 @@ public final class PreferenceScreen extends PreferenceGroup implements AdapterVi
|
||||
|
||||
private void showDialog(Bundle state) {
|
||||
Context context = getContext();
|
||||
ListView listView = new ListView(context);
|
||||
bind(listView);
|
||||
if (mListView != null) {
|
||||
mListView.setAdapter(null);
|
||||
}
|
||||
mListView = new ListView(context);
|
||||
bind(mListView);
|
||||
|
||||
// Set the title bar if title is available, else no title bar
|
||||
final CharSequence title = getTitle();
|
||||
Dialog dialog = mDialog = new Dialog(context, TextUtils.isEmpty(title)
|
||||
? com.android.internal.R.style.Theme_NoTitleBar
|
||||
: com.android.internal.R.style.Theme);
|
||||
dialog.setContentView(listView);
|
||||
dialog.setContentView(mListView);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
dialog.setTitle(title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user