I decided to post two question in one post, because it’s quite same problem.
I need to know when screen is ON or OFF so i can turn LED. The second one I need to know if my applicaiton is in backgorund or it is in foreground, to manage sending notification on some actiong when app is in background.
There have been similar questions on Stackoverflow earlier. Here are links to a few of them:
How to determine if one of my activities is in the foreground
android:how to check if application is running in background
How can I tell if Android app is running in the foreground?