// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the ActivityService.
ActivityServiceInterface activityService =
user.getService(DfpService.V201308.ACTIVITY_SERVICE);
// Set the ID of the activity group to create the activities for.
Integer activityGroupId = Integer.parseInt("INSERT_ACTIVITY_GROUP_ID_HERE");
// Create a daily visits activity.
Activity dailyVisitsActivity = new Activity();
dailyVisitsActivity.setName("Activity #" + new Random().nextLong());
dailyVisitsActivity.setActivityGroupId(activityGroupId);
dailyVisitsActivity.setType(ActivityType.DAILY_VISITS);
// Create a custom activity.
Activity customActivity = new Activity();
customActivity.setName("Activity #" + new Random().nextLong());
customActivity.setActivityGroupId(activityGroupId);
customActivity.setType(ActivityType.CUSTOM);
// Create the activities on the server.
Activity[] activities =
activityService.createActivities(new Activity[] {dailyVisitsActivity, customActivity});
for (Activity activity : activities) {
System.out.printf("An activity with ID \"%d\", name \"%s\", and type \"%s\" was created.\n",
activity.getId(), activity.getName(), activity.getType());
}