안드로이드 판단이 프론트에 적용될지 백엔드에 적용될지

1169 단어 android 개발
때때로 우리는 자신의 응용 프로그램이 프론트 데스크톱이나 백엔드에 있는지 확인하고 서로 다른 상태에 따라 처리해야 한다.
/**
     *          
     *
     * @param mContext
     * @return
     */
    public boolean isAppForground(Context mContext) {
        ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
        List tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(mContext.getPackageName())) {
                return false;
            }
        }
        return true;
    }

좋은 웹페이지 즐겨찾기