I use certain sounds to notify the user of certain events. However, I do not want the app to notify the user with sounds if the activity is not on foreground.
How can I check if the app is running on background or not?
Expanding on mco's answer, your GCMIntentService
needs to do something that will trigger work in a foreground activity of yours, if you have a foreground activity. Typically, you will do this by setting up your activities to respond to some sort of message in onResume()
and removing that in onPause()
.
"Some sort of message" could be:
Intent
sent via LocalBroadcastManager
Intent
sent via the classic sendBroadcast()