David went from crying out to God in despair to realizing only God could help him. He knew he could not rely on any person who knew and would understand what he was going through.
David is still pleading with God to listen to him as he searches in the past to see the hand of God in his life, and also he saw how he showed him the way to go.
Here he sees that life is fleeting like a shadow and looks at his wonderful creation, and realizes how powerful God is, and to put his trust in him.
In this psalm, he praises God and says he will pass it on to future generations. He is especially thankful for the gift of salvation.