Android判断当前的Activity

private boolean inOBDActivity() {

		ActivityManager am = (ActivityManager) this
				.getSystemService(Context.ACTIVITY_SERVICE);
		List tasks = am.getRunningTasks(1);

		if (!tasks.isEmpty()) {
			ComponentName topActivity = tasks.get(0).topActivity;
			return topActivity.getClassName().endsWith(
					OBDMainActivity.class.getName());
		}
		return false;
	}

你可能感兴趣的:(Android)