How to programmatically clear application data

You can use the package-manager tool to clear data for installed apps (similar to pressing the 'clear data' button in the app settings on your device). So using adb you could do:

adb shell pm clear my.wonderful.app.package

Following up to @edovino's answer, the way of clearing all of an application's preferences programmatically would be

private void clearPreferences() {
    try {
        // clearing app data
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("pm clear YOUR_APP_PACKAGE_GOES HERE");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Warning: the application will force close.