When John Quincy Adams left the White House after his defeat in the election of 1828, he thought his public life had ended.