I haven't been in this situation but one of my DDs and also one of my closest friends have been through it. In both cases, their husbands' behaviour changed, they became unpleasant and secretive, and both women felt that there was something wrong. DD's suspicions were confirmed when she found payment for an overnight stay in a hotel near his office, when he was supposed to be miles away on a business trip to Ireland. He was having an affair with a colleague. My friend didn't really know what was wrong until her DH announced that he was leaving her for another woman. Their marriage ended but DD and her DH managed to patch things up. That was nearly 20 years ago and they have made their marriage work. It wasn't easy in the beginning, though, as DD felt so hurt and betrayed.
I also have a friend whose partner had, and maybe still has, an online porn addiction. She found it on his phone and he admitted that he had done it for years, even at the most inappropriate times and places. She has been through hell. They have talked for hours, and both have seen therapists (in her case, because her self-esteem and self-confidence were shattered), but he has really struggled to give it up. He has lied repeatedly, but she is more IT-savvy than him and has found it on his phone when he has thought that he deleted it. It seems that he really wants to stop now but it's as addictive as heroin and much easier to obtain. They want to make the relationship work but the trust is badly damaged.
It seems to me that the OP's partner is acting very much like these men. Secretive behaviour and/or unpleasantness isn't a good sign. In the cases of the men who were having affairs, both of them accused their wives of being paranoid for thinking that something was wrong. If he says that, ignore him! The flirting isn't a good sign either.
Basically, it would be a good idea to think about what you might want - a divorce? or to try again? - and to make sure that you know your rights. Everything might be OK but it's wise to be prepared. And I wouldn't have any compunction about spying on him, to find out what he is up to.