Ok, on android there are two ways to track such event in activity. Activity class reference in docs covers both cases: http://developer.android.com/reference/android/app/Activity.html
onResume() Java methods called when another apps appears on top of current app, and only
onStop() actually called when app comes to sleep and then resumes. Actually there’re no garantues that
onStop() will be called whenever — as android developers blog post tells.
There is also method
onWindowFocusChanged() in Activity class, system window that changes volume settings causes losing focus for underlying apps.