am 0c8d57d1: Merge "Fix Activity ref-leak in NFC dispatch API."
* commit '0c8d57d124d917721890b0aa4a152f9c9c7d317f': Fix Activity ref-leak in NFC dispatch API.
This commit is contained in:
@@ -20,7 +20,7 @@ import android.app.Activity;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Manages NFC API's that are coupled to the life-cycle of an Activity.
|
||||
@@ -38,7 +38,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub {
|
||||
static final Boolean DBG = false;
|
||||
|
||||
final NfcAdapter mAdapter;
|
||||
final HashMap<Activity, NfcActivityState> mNfcState; // contents protected by this
|
||||
final WeakHashMap<Activity, NfcActivityState> mNfcState; // contents protected by this
|
||||
final NfcEvent mDefaultEvent; // can re-use one NfcEvent because it just contains adapter
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ public final class NfcActivityManager extends INdefPushCallback.Stub {
|
||||
|
||||
public NfcActivityManager(NfcAdapter adapter) {
|
||||
mAdapter = adapter;
|
||||
mNfcState = new HashMap<Activity, NfcActivityState>();
|
||||
mNfcState = new WeakHashMap<Activity, NfcActivityState>();
|
||||
mDefaultEvent = new NfcEvent(mAdapter);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,13 @@ public final class NfcActivityManager extends INdefPushCallback.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onDestroy hook from fragment attached to activity
|
||||
*/
|
||||
public void onDestroy(Activity activity) {
|
||||
mNfcState.remove(activity);
|
||||
}
|
||||
|
||||
public synchronized void setNdefPushMessage(Activity activity, NdefMessage message) {
|
||||
NfcActivityState state = getOrCreateState(activity, message != null);
|
||||
if (state == null || state.ndefMessage == message) {
|
||||
@@ -214,4 +221,5 @@ public final class NfcActivityManager extends INdefPushCallback.Stub {
|
||||
callback.onNdefPushComplete(mDefaultEvent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,4 +80,14 @@ public final class NfcFragment extends Fragment {
|
||||
sNfcActivityManager.onPause(getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (sNfcActivityManager != null) {
|
||||
sNfcActivityManager.onDestroy(getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user