refactor the code for any activity can get the message and media