android - Check application is minimized/background -
i surprised!
because not able identify application in foreground or background,
when pressed home button , application not in foreground. after have used check application running in foreground or not.
public boolean isapponforeground() { activitymanager activitymanager = (activitymanager) context.getsystemservice(context.activity_service); list<runningappprocessinfo> appprocesses = activitymanager.getrunningappprocesses(); if (appprocesses == null) { homecoming false; } final string packagename = context.getpackagename(); (runningappprocessinfo appprocess : appprocesses) { if (appprocess.importance == runningappprocessinfo.importance_foreground && appprocess.processname.equals(packagename)) { homecoming true; } } homecoming false; } it returns true if application not in foreground.
note: application have 2 services, 1 service canceled when application removed recent task list( that have achieved.) 2 service canceled when application goes in background. (that check wifi signal strength.)
how know app foreground or background?
how stop service when application not in foreground?
rely on activity callback methods, such onpause(), onstop() , onresume(), give hints on current state of activity. activity reference gives broad explanation of every of methods.
android android-activity service
No comments:
Post a Comment