You can try onWindowFocusChanged() and see if this helps:
This is the best indicator of whether this activity is visible to the user. The default implementation clears the state of key tracking, so you should always call it.
This is written about onResume() :
Keep in mind that onResume is not the best indicator that your activity is visible to the user; A system window, such as a key lock, may be in front. Use onWindowFocusChanged (boolean) to know for sure that your activity is visible to the user (for example, to resume the game).
source share