Correctly unregister receiver in "join wifi" swap view.
Previously the receiver was added but never removed. The result is that once a swap session is cancelled, the receiver still gets broadcasts.
This commit is contained in:
parent
1af6dbc19e
commit
b19861226a
@ -60,19 +60,23 @@ public class JoinWifiView extends RelativeLayout implements SwapWorkflowActivity
|
|||||||
});
|
});
|
||||||
refreshWifiState();
|
refreshWifiState();
|
||||||
|
|
||||||
// TODO: This is effectively swap state management code, shouldn't be isolated to the
|
|
||||||
// WifiStateChangeService, but should be bundled with the main swap state handling code.
|
|
||||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
|
||||||
new BroadcastReceiver() {
|
onWifiStateChange,
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
refreshWifiState();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new IntentFilter(WifiStateChangeService.BROADCAST)
|
new IntentFilter(WifiStateChangeService.BROADCAST)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove relevant listeners/receivers/etc so that they do not receive and process events
|
||||||
|
* when this view is not in use.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(onWifiStateChange);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Listen for "Connecting..." state and reflect that in the view too.
|
// TODO: Listen for "Connecting..." state and reflect that in the view too.
|
||||||
private void refreshWifiState() {
|
private void refreshWifiState() {
|
||||||
TextView descriptionView = (TextView) findViewById(R.id.text_description);
|
TextView descriptionView = (TextView) findViewById(R.id.text_description);
|
||||||
@ -138,4 +142,11 @@ public class JoinWifiView extends RelativeLayout implements SwapWorkflowActivity
|
|||||||
public String getToolbarTitle() {
|
public String getToolbarTitle() {
|
||||||
return getResources().getString(R.string.swap_join_same_wifi);
|
return getResources().getString(R.string.swap_join_same_wifi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final BroadcastReceiver onWifiStateChange = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
refreshWifiState();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user