android detect user switching from/to HOME -


i have appwidget @ home , updated periodically. want stop update if home not visiable. use service register screen on/off receiver start/stop updating appwidget when screen on/off. don't know how detect if screen on user focusing on else (i.e. home not @ foreground). how can detect if user switch from/to home in service or receiver (it's appwidget , don't have activity on hand when happens)?

as far know, there no direct api detect whether home in foreground or background.

but following snippet tell whether user @ home or not.

if (mactivitymanager.getrunningtasks().get(0).topactivity.getpackagename().equals("com.android.launcher") {  //home   } 

disclaimer: above code work default launcher (com.android.launcher). so, if user using third-party launcher, can't detect if don't know package name of launcher.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -