I will bless the Lord at all times. His praise shall continually be in my mouth."- Psalms 34:1b.
When you read this plalms, it does not start out with 'I will bless the Lord at all times.' It ends with "I will bless the Lord at all times: His praise shall continually be in my mouth. David was forced to flee his country due to Sauls hatred for him. David did not go too far away and when it became known that David was near, King Abimelech was made aware of Davids presence close by. David acted like a mad man so he would not be removed from his country by the king. It worked.
Imagine someone acting unstable just so they could stay close to that which they love. David was disliked greatly by Saul. When you study the relationship between David and Saul you can see the jealousy and disdain Saul had for David. Why? Everything Saul told David to do, he did it. David never complained nor did he try to take Sauls place even after God made David aware that he would replace Saul as king.
Through all he went through, David still wanted to bless the Lord at all times. In good times. In hard times. In evil times. In hurtful times.'I will bless the Lord at all times. His praise shall continually be in my mouth.
A Psalm of David when he changed his behavior before Abimelech; who drove him away, and he departed.- Psalms 34:1