David was described by God as a man after His own heart. That is very high praise considering David did some pretty bad things in his life.
I think one of the keys to David’s life is prayer. He was always in communication with God. He praised God in the goods times and cried out for help in the bad.
In Psalm 86 we see an example of one of David’s prayers…
Psalm 86:1-7 NLT – Bend down, O LORD, and hear my prayer; answer me, for I need your help.  Protect me, for I am devoted to you. Save me, for I serve you and trust you. You are my God.  Be merciful to me, O Lord, for I am calling on you constantly.  Give me happiness, O Lord, for I give myself to you.  O Lord, you are so good, so ready to forgive, so full of unfailing love for all who ask for your help.  Listen closely to my prayer, O LORD; hear my urgent cry.  I will call to you whenever I’m in trouble, and you will answer me.
In this prayer David poured out his heart to God. He asked for God to hear his prayer, and for protection, salvation, mercy, happiness and help. He also devoted himself to God and said that he served and trusted God.
David truly was a man after God’s own heart. One of the keys is his prayer life. What a great example for us today.