title: how to call an activity when getting incoming call.
body: <p>Hi all i want to invoke a my own activity over the default incoming call activity.. i have done this with using broadcast receivers i am invoking my activity when getting incoming call. but it is working fine for first time from second time when i get incoming call then default incoming call activity is coming over my activity . i don't know what is the problem can any one please help me .. </p>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.satish.service"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
  &lt;uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
  &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name" &gt;
      &lt;receiver
          android:name="MyCallReceiver"
          android:enabled="true" &gt;
          &lt;intent-filter android:priority="10"&gt;
              &lt;action android:name="android.intent.action.PHONE_STATE" &gt;
  
              &lt;/action&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;receiver
          android:name="TestReceiver"
          android:enabled="true" &gt;
          &lt;intent-filter android:priority="10"&gt;
              &lt;action android:name="jason.wei.custom.intent.action.TEST" &gt;
              &lt;/action&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;activity
          android:name="CallActivity"
          android:clearTaskOnLaunch="true"
          android:launchMode="singleTask" &gt;
          &lt;intent-filter android:priority="1000"&gt;&lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Java Code:</p>
  
  <pre><code>public class MyCallReceiver extends BroadcastReceiver{
   public static final String CUSTOM_INTENT = "jason.wei.custom.intent.action.TEST";
  Context context = null;
   private static final String TAG = "Phone call";
  
  
  
  public void onReceive(Context context, Intent intent) {
  
      Bundle extras = intent.getExtras();
      if (extras != null) {
          String state = extras.getString(TelephonyManager.EXTRA_STATE);
          Log.w("DEBUG", state);
          if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
  
                      Intent i = new Intent();
                      i.setAction(CUSTOM_INTENT);
                      context.sendBroadcast(i);
  
          }
      }
  }
  }
  
  
  public class TestReceiver extends BroadcastReceiver {
  
  public void onReceive(Context context, Intent intent) {
      if (intent.getAction().equals(MyCallReceiver.CUSTOM_INTENT)) {
          System.out.println("GOT THE INTENT");
          context.startActivity(new Intent(context, CallActivity.class)
                  .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
      }
  }
  }
  
  public class CallActivity extends Activity implements OnClickListener{
  private ITelephony telephonyService;
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      setTheme(android.R.style.Theme_Dialog);
      ((Button)findViewById(R.id.call)).setOnClickListener(this);
      ((Button)findViewById(R.id.end)).setOnClickListener(this);
      TelephonyManager telephony = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);  
  
        try {
             Class c = Class.forName(telephony.getClass().getName());
             Method m = c.getDeclaredMethod("getITelephony");
             m.setAccessible(true);
             telephonyService = (ITelephony) m.invoke(telephony);
            } catch (Exception e) {
             e.printStackTrace();
            }
  }
  
  @Override
  public void onClick(View arg0) {
      switch (arg0.getId()) {
      case R.id.call:
  
          telephonyService.answerRingingCall();
          break;
  
      case R.id.end:
          telephonyService.endCall();
          finish();
          break;
  
      default:
          break;
      }
  }
  }
  </code></pre>