title: Fragments and Broadcast Receivers
body: <p>I have an <code>activity</code> with two <code>fragments</code>. I am not using <code>&lt;fragment/&gt;</code> tags, I have two classes that extends <code>Fragment</code>, in that fragment, I have:</p>
  
  <pre><code>    @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.bfragment, container, false); // this will inflate the Fragment in activity.
      }
  </code></pre>
  
  <p>Now the problem is, I am receiving some broadcast receivers in activity from which some receivers update the UI from first fragment and some updates the UI from 2nd. </p>
  
  <p>One of my broadcast receiver defined in my main acitivity is:</p>
  
  <pre><code>private BroadcastReceiver bcReceived = new BroadcastReceiver() {
  
          @Override
          public void onReceive(Context arg0, Intent intent) {
              Log.d("", "BC Object Received");
  
              ActionBar actionbar = getActionBar();
              actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
              ActionBar.Tab bTab = actionbar.newTab().setText("B");
              Fragment fragment = new BFragment();
              bTab.setTabListener(new MyTabsListener(fragment));
              actionbar.addTab(bTab, true);
  
              final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.bTable);  // Getting null pointer exception here. linearLayout is not getting initialized.
  </code></pre>
  
  <p>I want to use the above linearLayout and use it to inflate a view in it. But getting NPE.</p>
  
  <p>here, when some broadcast receivers update the first fragment, it works properly, but when a broadcast receiver updates the 2nd fragment from activity, I get NPE.</p>
  
  <p><strong>My question is:</strong> How and where should I update the fragment? Should it be inside my activity? if yes then in which method? if not then where should I update the fragment?</p>
  
  <p>Please help me!!!</p>