Media playback is unsupported on your device Media caption Ricky Gervais says David Bowie sent him “the funniest emails” - two weeks before he died.

Ricky Gervais has revealed he was exchanging emails with David Bowie two weeks before his death but that Bowie kept the state of his health private.

Gervais told Radio 5 live he contacted the musician to say he loved his new album Blackstar and Bowie replied.

"[His death] was a total surprise. I was emailing him two weeks before, so he must have known. He kept it from everyone," said Gervais.

The rock star died in January at the age of 69.

As a very private person, Bowie's death came as a big shock and prompted a global outpouring of grief.

"What dignity. He was an amazing man. It was something for him and his family. Dignity to the end," the comedian said of his friend's secrecy on the Afternoon Edition programme.

Image copyright PA Image caption David Bowie was 'a fan of comedy' and wrote a spoof song mocking Ricky Gervais's character Andy in Extras

"And amazing work to the end," Gervais added.

Their friendship had started more than a decade ago.

"After The Office we sort of became pen pals," said Gervais.

"I hung out with him when I went to New York. I hung out with him here when he came to England."

Bowie appeared in Gervais's comedy series Extras, which was a hit largely due to the cameo celebrity guest role in each episode.

The episode featuring the singer has become popular due to his spoof song about Gervais's character Andy.

Bowie writes a song called Little Fat Man after Andy approaches him in a bar. The lyrics focus on Andy's "pug-nosed face" and say he "sold his soul for a shot at fame".

Bowie also appears in a mock interview, saying: "My background is in serious acting so doing something like Extras is a piece of cake for me."

Image copyright Netflix Image caption Special Correspondents sees Ricky Gervais (centre) play an unscrupulous radio journalist who with his technician (Eric Bana - left) fake their own kidnapping

Gervais told Radio 5 live: "He was a fan of comedy. It's funny. I was a failed pop star. He loved comedy.

"He was amazing in Extras. I sent him the lyrics and I said: 'Do something quite retro like Life On Mars and he went: 'Oh yeah, I'll just knock off a quick Life On Mars'.

Gervais spoke to the BBC ahead of the release of his new film for Netflix, Special Correspondents on Friday.

The satirical comedy, written and directed by Gervais, features an unscrupulous radio journalist and his technician who bite off more than they can chew when they fake their own kidnapping during a rebel uprising in South America. Instead, they are holed up in a hideaway in New York.

The film also stars Eric Bana and was originally set for a cinema release, until Netflix bought the rights.

Gervais said he believed the streaming service would "bring the auteur back to film-making".

"As an artist you want as many people as possible to see your work with no interference. And usually I've gone onto fringe channels BBC Two, HBO, Channel 4," he said.

"I've avoided doing a network comedy, because I wouldn't get my own way. Even though it would get more viewers it wouldn't be mine. And then Netflix come along and say you can still get your own way and the sky's the limit for ratings. They have 75 million subscribers now."

Gervais will still make films for the big screen. In August, David Brent: Life on The Road, a spin-off from the comedy series that made Gervais a star, will be released at cinemas.

It follows his character David Brent from The Office, 15 years after the end of the show.

Gervais has often spoken about how pleased he was The Office ended after two series, the same as Fawlty Towers, but insists that bringing back the character will not damage the show's reputation.

"I stand by I'm not going to do The Office again," he said. "That would be weird, all the same people sitting at the same desks at a paper merchants in Slough.

"But because it's a documentary, I think it has credibility that this man would have another bite at the cherry.

"He thinks this is like Martin Scorcese following the Rolling Stones around. Whereas it's really a 'where are they now' file. It's not the Office. It mustn't be. That was very then."

The interview with Ricky Gervais will be heard on Afternoon Edition on Radio 5 live at 13:00 BST on Monday 25 April.