0

I have an activity which occurs when a call is received. However, it only works the first time a call is received. What's the best way to make it work for subsequent calls? Should I do something besides startActivity (i.e. is there something like bringActivityToForeground?) or do I need to end the activity when the call is dropped? How would I end an activity?

public class CallReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
      Intent myIntent = new Intent(context, MyActivity.class);
      context.startActivity(myIntent);

    } else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
      // TODO: remove the screen?
    }    
  }
}
Ben McCann
  • 18,548
  • 25
  • 83
  • 101

1 Answers1

0

Have you tried explicitly Resuming the Activity once the call is received?

Jade Byfield
  • 4,668
  • 5
  • 30
  • 41
  • How would I do that? I think I probably want to end the activity when the call is answered or dropped instead, but I don't know how to do either. – Ben McCann Oct 09 '12 at 23:16
  • 1
    You could declare the activity `noHistory` attribute in your androidmanifest.xml to `true`. This will finish the activity when it is no longer needed. – Daniel Oct 09 '12 at 23:25