Reputation: 11050
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?
Upvotes: 0
Views: 626
Reputation: 1006914
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()
Upvotes: 4
Reputation: 422
In the Activity cycle, onResume is called when the app becomes visible (foreground) and onPause is called when it is not visible (background).
You can use these functions to do whatever you want to do when the app is background/foreground.
Upvotes: 3