A former police officer has been accused of stalking and secretly using his ex-boyfriend’s phone to delete messages from “romantic rivals” before allegedly killing the man, a jury has been told.