Bug 1175355 - Add WeakReference into PreferenceFragment's Handler. r=nalexander

--HG--
extra : commitid : Kk073S7nGJ0
extra : rebase_source : 5bbfb60983b290e3f1a12fc768307f353f6c97d2
This commit is contained in:
Michael Comella 2015-06-24 16:48:25 -07:00
Родитель 1a8f3da884
Коммит 152d8dd058
1 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -17,6 +17,7 @@
package org.mozilla.gecko.background.preferences; package org.mozilla.gecko.background.preferences;
import org.mozilla.gecko.R; import org.mozilla.gecko.R;
import org.mozilla.gecko.util.WeakReferenceHandler;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -49,21 +50,28 @@ public abstract class PreferenceFragment extends Fragment implements PreferenceM
private static final int MSG_BIND_PREFERENCES = 1; private static final int MSG_BIND_PREFERENCES = 1;
// This triggers "This Handler class should be static or leaks might occur". private static class PreferenceFragmentHandler extends WeakReferenceHandler<PreferenceFragment> {
// The issue is that the Handler references the Fragment; messages targeting public PreferenceFragmentHandler(final PreferenceFragment that) {
// the Handler reference it; and if such messages are long lived, the Fragment super(that);
// cannot be GCed. This is not an issue for us; our messages are short-lived. }
private final Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
final PreferenceFragment that = mTarget.get();
if (that == null) {
return;
}
switch (msg.what) { switch (msg.what) {
case MSG_BIND_PREFERENCES: case MSG_BIND_PREFERENCES:
bindPreferences(); that.bindPreferences();
break; break;
} }
} }
}; }
private final Handler mHandler = new PreferenceFragmentHandler(this);
final private Runnable mRequestFocus = new Runnable() { final private Runnable mRequestFocus = new Runnable() {
@Override @Override