Understanding urban functions and their relationships with human activities has great implications for smart and sustainable urban development. In this study, we present a novel approach to uncovering urban functions by aggregating human activities inferred from mobile phone positioning and social media data. First, the homes and workplaces (of travelers) are estimated from mobile phone positioning data to annotate the activities conducted at these locations. The remaining activities (such as shopping, schooling, transportation, recreation and entertainment) are labeled using a hidden Markov model with social knowledge learned from social media check-in data over a lengthy period. By aggregating identified human activities, hourly urban functions are inferred, and the diurnal dynamics of those functions are revealed. An empirical analysis was conducted for the case of Shenzhen, China. The results indicate that the proposed approach can capture citywide dynamics of both human activities and urban functions. It also suggests that although many urban areas have been officially labeled with a single land-use type, they may provide different functions over time depending on the types and range of human activities. The study demonstrates that combining different data on human activities could yield an improved understanding of urban functions, which would benefit short-term urban decision-making and long-term urban policy making.