This typically happens when someone was attacking you when you logged on to the game. The notification that you were attacked only appears after the fight is over.
The notification also does not appear when you are on certain screens in the game. You mentioned that you were fighting the Titan and playing levels. These are 2 of the screens where the notification does not appear.
The most likely scenario is: Your opponent had just attacked your defense team when you logged in. By the time the raid was completed you were on a screen that suppresses the notification. Once you got to a screen where this notification was allowed, you were notified that you had been attacked.
This happens frequently and gives the illusion that you were attacked while online. Of course, if you’re in the top 100 then being attacked while you’re online is allowed. I’m assuming that Is not the case, but congrats if you are!