private String adbCurrentActivity() throws Exception {
    String adbPath = System.getenv("ANDROID_HOME")+"/platform-tools/"+"adb";
    String output = execCmd(adbPath + " shell dumpsys window windows");

    String activityLines = "";
    String[] lines = output.split("\n");
    for (int i = 0; i < lines.length; i++) {
      if (lines[i].contains("mCurrentFocus") || lines[i].contains("mFocusedApp")) {
        activityLines += lines[i];
      }
    }

    return activityLines;
  }
Requires ANDROID_HOME to be set in enviroment.
@throws Exception
selendroid-test-app/src/test/java/io/selendroid/nativetests/BackgroundAppTest.java