Fix broadcast manager usage.

Change-Id: Ifa4b461b537e40a65753c49f848dd8e4357e82f7
This commit is contained in:
Artur Dryomov
2013-07-12 01:21:30 +03:00
committed by Michael Meeks
parent 5fe6ee0f92
commit 77ba1b25d1
2 changed files with 16 additions and 6 deletions

View File

@@ -96,7 +96,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
mIntentsReceiver = new IntentsReceiver(this);
IntentFilter aIntentFilter = buildIntentsReceiverFilter();
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mIntentsReceiver, aIntentFilter);
getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter);
}
private static class IntentsReceiver extends BroadcastReceiver {
@@ -137,6 +137,12 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
return aIntentFilter;
}
private LocalBroadcastManager getBroadcastManager() {
Context aContext = getActivity().getApplicationContext();
return LocalBroadcastManager.getInstance(aContext);
}
public void setUpPinValidationInstructions(String aPin) {
TextView aPinTextView = (TextView) getView().findViewById(R.id.text_pin);
aPinTextView.setText(aPin);
@@ -152,8 +158,6 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
}
public void setUpPresentation() {
// TODO: implement
getActivity().finish();
}
@@ -193,7 +197,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
private void unregisterIntentsReceiver() {
try {
getActivity().unregisterReceiver(mIntentsReceiver);
getBroadcastManager().unregisterReceiver(mIntentsReceiver);
} catch (IllegalArgumentException e) {
// Receiver not registered.
// Fixed in Honeycomb: Androids issue #6191.

View File

@@ -117,7 +117,7 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
mIntentsReceiver = new IntentsReceiver(this);
IntentFilter aIntentFilter = buildIntentsReceiverFilter();
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mIntentsReceiver, aIntentFilter);
getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter);
}
private static final class IntentsReceiver extends BroadcastReceiver {
@@ -142,6 +142,12 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
return aIntentFilter;
}
private LocalBroadcastManager getBroadcastManager() {
Context aContext = getActivity().getApplicationContext();
return LocalBroadcastManager.getInstance(aContext);
}
public void loadComputers() {
if (!isServiceBound()) {
return;
@@ -205,7 +211,7 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
private void unregisterIntentsReceiver() {
try {
getActivity().unregisterReceiver(mIntentsReceiver);
getBroadcastManager().unregisterReceiver(mIntentsReceiver);
} catch (IllegalArgumentException e) {
// Receiver not registered.
// Fixed in Honeycomb: Androids issue #6191.