Index: /trunk/src/bp-groups/bp-groups-classes.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-classes.php	(revision 8396)
+++ /trunk/src/bp-groups/bp-groups-classes.php	(revision 8397)
@@ -1708,9 +1708,18 @@
 		}
 
-		// For 'last_joined' and 'first_joined' types, we force
-		// the order according to the query performed in
-		// BP_Group_Member_Query::get_group_members(). Otherwise, fall
-		// through and let BP_User_Query do its own ordering.
-		if ( in_array( $query->query_vars['type'], array( 'last_joined', 'first_joined' ) ) ) {
+		// For 'last_joined', 'first_joined', and 'group_activity'
+		// types, we override the default orderby clause of
+		// BP_User_Query. In the case of 'group_activity', we perform
+		// a separate query to get the necessary order. In the case of
+		// 'last_joined' and 'first_joined', we can trust the order of
+		// results from  BP_Group_Member_Query::get_group_members().
+		// In all other cases, we fall through and let BP_User_Query
+		// do its own (non-group-specific) ordering.
+		if ( in_array( $query->query_vars['type'], array( 'last_joined', 'first_joined', 'group_activity' ) ) ) {
+
+			// Group Activity DESC
+			if ( 'group_activity' == $query->query_vars['type'] ) {
+				$gm_ids = $this->get_gm_ids_ordered_by_activity( $query, $gm_ids );
+			}
 
 			// The first param in the FIELD() clause is the sort column id
@@ -1766,4 +1775,47 @@
 		// Don't filter other BP_User_Query objects on the same page
 		remove_action( 'bp_user_query_populate_extras', array( $this, 'populate_group_member_extras' ), 10, 2 );
+	}
+
+	/**
+	 * Sort user IDs by how recently they have generated activity within a given group.
+	 *
+	 * @since  BuddyPress (2.1.0)
+	 *
+	 * @param BP_User_Query $query BP_User_Query object.
+	 * @param array $gm_ids array of group member ids.
+	 * @return array
+	 */
+	public function get_gm_ids_ordered_by_activity( $query, $gm_ids = array() ) {
+		global $wpdb;
+
+		if ( empty( $gm_ids ) ) {
+			return $gm_ids;
+		}
+
+		if ( ! bp_is_active( 'activity' ) ) {
+			return $gm_ids;
+		}
+
+		$activity_table = buddypress()->activity->table_name;
+
+		$sql = array(
+			'select'  => "SELECT user_id, max( date_recorded ) as date_recorded FROM {$activity_table}",
+			'where'   => array(),
+			'groupby' => 'GROUP BY user_id',
+			'orderby' => 'ORDER BY date_recorded',
+			'order'   => 'DESC',
+		);
+
+		$sql['where'] = array(
+			'user_id IN (' . implode( ',', wp_parse_id_list( $gm_ids ) ) . ')',
+			'item_id = ' . absint( $query->query_vars['group_id'] ),
+			$wpdb->prepare( "component = %s", buddypress()->groups->id ),
+		);
+
+		$sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] );
+
+		$group_user_ids = $wpdb->get_results( "{$sql['select']} {$sql['where']} {$sql['groupby']} {$sql['orderby']} {$sql['order']}" );
+
+		return wp_list_pluck( $group_user_ids, 'user_id' );
 	}
 }
Index: /trunk/src/bp-groups/bp-groups-template.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-template.php	(revision 8396)
+++ /trunk/src/bp-groups/bp-groups-template.php	(revision 8397)
@@ -2438,4 +2438,9 @@
 			<option value="last_joined"><?php _e( 'Newest', 'buddypress' ); ?></option>
 			<option value="first_joined"><?php _e( 'Oldest', 'buddypress' ); ?></option>
+
+			<?php if ( bp_is_active( 'activity' ) ) : ?>
+				<option value="group_activity"><?php _e( 'Group Activity', 'buddypress' ); ?></option>
+			<?php endif; ?>
+
 			<option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
 
Index: /trunk/tests/phpunit/testcases/groups/class-bp-group-member-query.php
===================================================================
--- /trunk/tests/phpunit/testcases/groups/class-bp-group-member-query.php	(revision 8396)
+++ /trunk/tests/phpunit/testcases/groups/class-bp-group-member-query.php	(revision 8397)
@@ -403,4 +403,170 @@
 	/**
 	 * @group type
+	 * @group group_activity
+	 */
+	public function test_get_with_type_group_activity_with_activity_component_disabled() {
+		$g = $this->factory->group->create();
+		$u1 = $this->create_user();
+		$u2 = $this->create_user();
+		$u3 = $this->create_user();
+		$c = buddypress()->groups->id;
+		$time = time();
+
+		$this->add_user_to_group( $u1, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
+		) );
+
+		$this->add_user_to_group( $u2, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
+		) );
+
+		$this->add_user_to_group( $u3, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u3,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u1,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u2,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
+		) );
+
+		// Deactivate activity component
+		$activity_active = isset( buddypress()->active_components['activity'] );
+		if ( $activity_active ) {
+			unset( buddypress()->active_components['activity'] );
+		}
+
+		$query_members1 = new BP_Group_Member_Query( array(
+			'group_id' => $g,
+			'type' => 'group_activity',
+		) );
+
+		$query_members2 = new BP_Group_Member_Query( array(
+			'group_id' => $g,
+			'type' => 'last_joined',
+		) );
+
+		if ( $activity_active ) {
+			buddypress()->active_components['activity'] = '1';
+		}
+
+		$this->assertSame( wp_list_pluck( $query_members2->results, 'ID' ), wp_list_pluck( $query_members1->results, 'ID' ) );
+	}
+
+	/**
+	 * @group type
+	 * @group group_activity
+	 */
+	public function test_get_with_type_group_activity() {
+		$g = $this->factory->group->create();
+		$u1 = $this->create_user();
+		$u2 = $this->create_user();
+		$u3 = $this->create_user();
+		$c = buddypress()->groups->id;
+		$time = time();
+
+		$this->add_user_to_group( $u1, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
+		) );
+
+		$this->add_user_to_group( $u2, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
+		) );
+
+		$this->add_user_to_group( $u3, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u3,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u1,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u2,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
+		) );
+
+		$query_members = new BP_Group_Member_Query( array(
+			'group_id' => $g,
+			'type' => 'group_activity',
+		) );
+
+		$ids = wp_parse_id_list( array_keys( $query_members->results ) );
+		$this->assertEquals( array( $u2, $u1, $u3 ), $ids );
+	}
+
+	/**
+	 * @group type
+	 * @group group_activity
+	 */
+	public function test_get_with_type_group_activity_no_dupes() {
+		$g = $this->factory->group->create();
+		$u1 = $this->create_user();
+		$c = buddypress()->groups->id;
+		$time = time();
+
+		$this->add_user_to_group( $u1, $g, array(
+			'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u1,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
+		) );
+
+		$this->factory->activity->create( array(
+			'component' => $c,
+			'type' => 'activity_update',
+			'user_id' => $u1,
+			'item_id' => $g,
+			'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
+		) );
+
+		$query_members = new BP_Group_Member_Query( array(
+			'group_id' => $g,
+			'type' => 'group_activity',
+		) );
+
+		$ids = wp_parse_id_list( array_keys( $query_members->results ) );
+		$this->assertEquals( array( $u1, ), $ids );
+	}
+	/**
+	 * @group type
 	 */
 	public function test_get_with_type_alphabetical() {
