I am launching an activity when receiving a ringing broadcast from the phone however this isn't ended (or closed) once call is answered or aborted. I need to end the activity in my else if but am unsure how to go about this? What would be the best method?
public class CallReceiver extends BroadcastReceiver {
Intent i;
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
assert state != null;
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
i = new Intent(context, IncomingCall.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
context.startActivity(i);
}
else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// WHAT GOES HERE?
}
}
}