android 判断activity是否在最上层

private boolean isTopActivity()
    {
        boolean isTop = false;
        ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
        DebugLog.d(TAG, "isTopActivity = " + cn.getClassName());
        if (cn.getClassName().contains(TAG))
        {
            isTop = true;
        }
        DebugLog.d(TAG, "isTop = " + isTop);
        return isTop;
    }

你可能感兴趣的:(Android开发)