Detect if app is in background

We created an app that does some long polling. It however seems the app on Android keeps longpolling even if the app is not active (running in the background).

Is there an event to detect/capture when the app is in sleep/inactive/suspension mode, so we can alter the long polling behavior for it when the event fires?

Take a look at this Pause and this Resume

Hope it helps.