private static final String ACTIVITY_GROUP_ID = "INSERT_ACTIVITY_GROUP_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
int activityGroupId) throws Exception {
// Get the ActivityService.
ActivityServiceInterface activityService =
dfpServices.get(session, ActivityServiceInterface.class);
// Create a daily visits activity.
Activity dailyVisitsActivity = new Activity();
dailyVisitsActivity.setName("Activity #" + new Random().nextInt(Integer.MAX_VALUE));
dailyVisitsActivity.setActivityGroupId(activityGroupId);
dailyVisitsActivity.setType(ActivityType.DAILY_VISITS);
// Create a custom activity.
Activity customActivity = new Activity();
customActivity.setName("Activity #" + new Random().nextInt(Integer.MAX_VALUE));
customActivity.setActivityGroupId(activityGroupId);
customActivity.setType(ActivityType.CUSTOM);
// Create the activities on the server.
Activity[] activities =
activityService.createActivities(new Activity[] {dailyVisitsActivity, customActivity});
for (Activity createdActivity : activities) {
System.out.printf("An activity with ID \"%d\", name \"%s\", and type \"%s\" was created.\n",
createdActivity.getId(), createdActivity.getName(), createdActivity.getType());
}