android - Attaching code to user turning on screen -
i'm trying work piece of code works when user turns on screen, event or piece of code called , ran. needs work when screen goes sleep , should have cancel feature stop occuring @ users command. suggest ideas on how code in android
if want when activity
become foreground or background can override onwindowfocuschanged
,
public void onwindowfocuschanged(boolean hasfocus){ if(hasfocus){ //activity become foreground } else{ //activity become background } }
if want based on screen state, regardless of applications activity visible or not need use broadcastreceiver
still need service or activity running on background check out question android: broadcast receiver screen on , screen off
Comments
Post a Comment