Detecting when an Android app is in foreground or background

It’s a rule: every Android app has its own logic, context and behaviors. And the solutions that may apply successfully to certain cases…