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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -