title: Communication between BroadcastReceiver and Activity - android
body: <p>I have a broadcast receiver in my app which is fired every time the user gets an incoming call. Now, when it happens, I need the broadcast receiver to invoke a specific method in a specific activity. Now, I tried to make this method static and therefore available, but something tells me it is a very bad idea.</p>
  <p>Accordingly, I tried to instantiate the broadcast receiver inside my activity without declaring it in my manifest but the problem is - when the app is off, the activity dosn't exist and therefore I can't invoke my method.</p>
  <p>So my question is - How can I invoke this method when the broadcast receiver is fired up, without making it &quot;public static&quot;?</p>
  <p>Here is my activity code(I have deleted the irrelevant parts)</p>
  <pre><code>package com.silverfix.ringo.activities;
  
  import com.silverfix.ringo.R;
  import com.silverfix.ringo.activities.fragments.DataManagerFragment;
  
  import android.app.ActionBar;
  import android.app.Activity;
  import android.app.FragmentTransaction;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  
  public class RingtonesActivity extends Activity{
  
      private DataManagerFragment dataManagerFragment;
      private IntentFilter filter;
      private BroadcastReceiver phoneCall;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_ringtones);
          ActionBar ab = getActionBar();
          ab.setDisplayShowTitleEnabled(false);
          ab.setDisplayHomeAsUpEnabled(true);
          dataManagerFragment = new DataManagerFragment();
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.add(dataManagerFragment, &quot;DataManagerFragment&quot;);
          ft.commit();
          filter = new IntentFilter();
          filter.addAction(&quot;android.intent.action.PHONE_STATE&quot;);
          phoneCall = new BroadcastReceiver() {
              
              @Override
              public void onReceive(Context context, Intent intent) {
                  dataManagerFragment.act();
              }
          };
          registerReceiver(phoneCall, filter);
      }
  }
  </code></pre>