How to show notification with buttons, when I close the app?

How to show notification bar after closing the app from foreground which have 2-3 buttons and image? I need three buttons one for start SoundSensor.Listen, One for Stop SoundSensor.Listen and another one for quit app & notification from background too.

The best option I can think about is to use the when Screen1 Back Press event to detect if the app was closed pressing the Back button
But I don’t think you can know when user closes the app, because Android destroys the activity after closing it, so no more code is executed

We have too some other events on screen one like On pause or On stop.