title: Broadcast manager not working in Fragment
body: <p>I have a BroadcastReceiver which is used to receive data from a BLE device. The same code is working fine in an Activity but not in Fragment. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>    public class HomeFragment extends Fragment implements LocationListener {
  
      Session session;
      TextView textViewName;
      TextView textViewSteps;
      TextView textViewCalories;
      TextView textViewDistance;
      TextView textViewFimos;
      ImageView imageViewInfo;
      public static final String TAG = "StepCounter";
  
      private UARTService mService = null;
      private BluetoothDevice evolutionDevice = null;
  
      private static final int UART_PROFILE_CONNECTED = 20;
      private static final int UART_PROFILE_DISCONNECTED = 21;
      private int mState = UART_PROFILE_DISCONNECTED;
  
      MyDatabase myDatabase;
      LocationManager service;
      private LocationManager locationManager;
      private String provider;
      double latitude, longitude;
      List&lt;Byte&gt; listBytes = new ArrayList&lt;&gt;();
      int rowNumber = 1;
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          View view = inflater.inflate(R.layout.fragment_home, container, false);
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
          init(view);
  
          return view;
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          service_init();
      }
  
      private void init(View view) {
  
          session = new Session(getActivity());
  
          myDatabase = new MyDatabase(getActivity());
  
          service = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
          boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
  
          if (!enabled) {
              Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
              startActivity(intent);
          }
  
          locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
          Criteria criteria = new Criteria();
          provider = locationManager.getBestProvider(criteria, false);
  
          if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              // TODO: Consider calling
              //    ActivityCompat#requestPermissions
              // here to request the missing permissions, and then overriding
              //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
              //                                          int[] grantResults)
              // to handle the case where the user grants the permission. See the documentation
              // for ActivityCompat#requestPermissions for more details.
              return;
          }
          Location location = locationManager.getLastKnownLocation(provider);
  
          // Initialize the location fields
          if (location != null) {
              System.out.println("Provider " + provider + " has been selected.");
              onLocationChanged(location);
          }
  
  
          textViewName = view.findViewById(R.id.textViewName);
          textViewSteps = view.findViewById(R.id.textViewSteps);
          textViewCalories = view.findViewById(R.id.textViewCalories);
          textViewDistance = view.findViewById(R.id.textViewDistance);
          textViewFimos = view.findViewById(R.id.textViewFimos);
          imageViewInfo = view.findViewById(R.id.imageViewInfo);
  
          try {
              textViewName.setText("Hi, " + session.getUser().getUser().getName());
          } catch (Exception e) {
  
          }
  
      }
  
      private void service_init() {
          System.out.println("----&gt;&gt;&gt;&gt;");
          Intent bindIntent = new Intent(getActivity().getApplicationContext(), UARTService.class);
          getActivity().bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
  
          LocalBroadcastManager.getInstance(getActivity()).registerReceiver(UARTStatusChangeReceiver, makeGattUpdateIntentFilter());
      }
  
      private ServiceConnection mServiceConnection = new ServiceConnection() {
          public void onServiceConnected(ComponentName className, IBinder rawBinder) {
              mService = ((UARTService.LocalBinder) rawBinder).getService();
              Log.d(TAG, "onServiceConnected mService= " + mService);
              if (!mService.initialize()) {
                  Log.e(TAG, "Unable to initialize Bluetooth");
                  getActivity().finish();
              }
  
          }
  
          public void onServiceDisconnected(ComponentName classname) {
              mService = null;
          }
      };
  
      private static IntentFilter makeGattUpdateIntentFilter() {
          final IntentFilter intentFilter = new IntentFilter();
          intentFilter.addAction(UARTService.ACTION_GATT_CONNECTED);
          intentFilter.addAction(UARTService.ACTION_GATT_DISCONNECTED);
          intentFilter.addAction(UARTService.ACTION_GATT_SERVICES_DISCOVERED);
          intentFilter.addAction(UARTService.ACTION_DATA_AVAILABLE);
          intentFilter.addAction(UARTService.DEVICE_DOES_NOT_SUPPORT_UART);
          return intentFilter;
      }
  
      private final BroadcastReceiver UARTStatusChangeReceiver = new BroadcastReceiver() {
  
          public void onReceive(Context context, Intent intent) {
              String action = intent.getAction();
  
              final Intent mIntent = intent;
              //*********************//
              if (action.equals(UARTService.ACTION_GATT_CONNECTED)) {
                  getActivity().runOnUiThread(new Runnable() {
                      public void run() {
                          System.out.println("------- Device Connected: " + evolutionDevice.getName() + " - " + evolutionDevice.getAddress());
                          mState = UART_PROFILE_CONNECTED;
                      }
                  });
              }
  
              //*********************//
              if (action.equals(UARTService.ACTION_GATT_DISCONNECTED)) {
                  getActivity().runOnUiThread(new Runnable() {
                      public void run() {
                          System.out.println("------- Device Disconnected");
                          mState = UART_PROFILE_DISCONNECTED;
                          mService.close();
                          evolutionDevice = null;
                      }
                  });
              }
  
              //*********************//
              if (action.equals(UARTService.ACTION_GATT_SERVICES_DISCOVERED)) {
                  mService.enableTXNotification();
              }
              //*********************//
              if (action.equals(UARTService.ACTION_DATA_AVAILABLE)) {
                  final byte[] txValue = intent.getByteArrayExtra(UARTService.EXTRA_DATA);
                  List&lt;Byte&gt; byteList = Bytes.asList(txValue);
                  combineArrays(byteList);
              }
              //*********************//
              if (action.equals(UARTService.DEVICE_DOES_NOT_SUPPORT_UART)) {
                  System.out.println("------- Device doesn't support UART. Disconnecting");
                  mService.disconnect();
              }
  
  
          }
      };
  
      @Override
      public void onResume() {
          super.onResume();
  
          if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              // TODO: Consider calling
              //    ActivityCompat#requestPermissions
              // here to request the missing permissions, and then overriding
              //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
              //                                          int[] grantResults)
              // to handle the case where the user grants the permission. See the documentation
              // for ActivityCompat#requestPermissions for more details.
              return;
          }
          locationManager.requestLocationUpdates(provider, 400, 1, this);
          Log.d(TAG, "onResume");
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          Log.d(TAG, "onDestroy()");
  
          try {
              LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(UARTStatusChangeReceiver);
          } catch (Exception ignore) {
              Log.e(TAG, ignore.toString());
          }
          getActivity().unbindService(mServiceConnection);
          mService.stopSelf();
          mService = null;
  
      }
  </code></pre>
  
  <p>The complete code in the same ay with a few changes in working fine in Activity. Any idea what might be the blocker.? Do I need to do something else in the fragment to receive the data from the Local Broadcast Manager.?</p>