android - How to determine if one of my activities is in the foreground -


i have implemented broadcastreceiver triggered alarmmanager. alarmmanager initialized on boot_completed. have declare receiver in manifest.

my problem want broadcastreceiver when none of own activities in foreground (aka user not interacting application). pull information remote server , don't want notify user if in application anyways.

so far have not managed find way determine if application in foreground. there way such thing? activitymanager tells me if application running not whether in foreground.

the problem pretty same described here: inform activity broadcastreceiver if in foreground

solution:

after evaluating several solutions want outline think best method deal activities in background/foreground.

the preferred way register broadcast receiver in onresume method of activity , deregister on activities on onpause. service or other background element need send broadcast intent specific action activity intercept.

if activity in foreground have intent receiver registered , able directly deal intent send service. if not in foreground not receive intent service invokved broadcast know nobody intercepted broadcast intent , able deal itself. eg launch desired activity, show notification etc.

the following answer: "is application running in background", summarizes solutions available background/foreground checking.

note:
answer suggested use activitymanager.getrunningappprocesses(), method appeared not reliable , usage discouraged. check link above details.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -