LONDON — Former President Barack Obama told Prince Harry in an interview broadcast Wednesday that people in leadership roles must be careful in their use of social media and warned against spending too much time immersed in the internet.

Obama did not, however, directly mention his successor, President Trump, who has made the use of Twitter a centerpiece of his presidency.

“One of the dangers of the internet is people can have entirely different realities. They can be just cocooned in information that reinforces their current biases,” he said.

He spoke with Harry in the prince’s capacity as guest editor of the BBC Radio 4 news program. Both men said the interview, recorded in Canada in September, was Obama’s first since leaving the presidency in January.

Obama said he felt serene the day he left the White House at the end of his second four-year term, despite the vast amount of work that remained unfinished.

Obama rejected gloomy prognostications about the state of the world, saying that in many ways the world is healthier and wealthier than it has ever been, making it perhaps the best time in history to be born.

He cited improved treatment of African-Americans and greatly expanded opportunities for young women as achievements of the past few generations that give him hope for the future.