Title bar clolor issue

Hello all.
I have an if else block which set title bar color to be red or blue according to condition. In else situation color is set to be red and it is working well. But at the same time I share some message on whatsApp, when I come back to app from whatsapp the tile bar color is automatically set as BLUE. I don,t know why?

You can see from screen shots; till sharing message on whatsapp Its color is red and system is abnormal but after coming back from whatsapp system is abnormal but color is not red. Last thing when I close this screen and initialize again it work well.

Kindly Help thanks alot.