Don't have Telegram yet? Try it now!
https://techpaliyal.com/how-to-detect-when-an-android-app-goes-to-the-background-and-come-back-to-the-foreground/
How to detect when an Android app goes to the background and come back to the foreground