Search code examples
androidbroadcastreceiver

Closing Activity when Call is disconnected before picking (missed call)


I have designed an app to intercept an incoming call and then once the default incoming call screen is loaded, I load my screen's activity to display Answer / Reject Buttons over sliders (overlay with translucent background) from the default activity. Everything works fine from functionality point of view, but when I am not able to pick the call and basically get a missed call, the default screen gets closed, but my overlayed buttons (my activity) remains open and I have to either press back / home button to get rid of those.

Is there any way, by which, when my activity opens, I can check if the call has been disconnected before picking it up and then close itself, so that user returns to his last used screen (or Home screen for that matter)?

Please suggest. Thanks Omkar Ghaisas


Solution

  • I got this to work by registering a receiver in my activity and then based on the call dicsonnect broadcast, I call finish() on my activity to come out of it, if the call has already been disconnected by calling party, before I can accept / reject it.