"Then We raised you up after your death that you may give thanks".
(Para No: 1 & Verse No: 56)
What is your opinion about Allah?. Did He need any thing ?. Did He need that we worship Him?. Did He need that we gave thanks to Him?. The answer is "No". Allah is above all these things. Allah did not need anything He is above of all. We need Him and He did not need us. He is above all that we worship Him if the whole world will against Him then He has no worries and if all the people worship Him still no happiness. We need Allah and Allah do not need us.
This is the common thing and common approach of a believers of Allah. But what we read in the above mentioned verse of Holy Quran. Allah raised the Israel's up after their death only that may they give thanks to Allah. Did you think Allah need the thanks of those who deny to believe in Allah until or unless they will not see the Allah with their own open eye's.
No Allah shows that the man are so selfish when He accept their prayers then they forgot Him and start the worship of idols again. Allah informed us that it is our habit. When we are in pain we cry and start praying from one Allah that He remove all bad things from us. But when the pain is removed then we just forgot the Allah. So we start try to give thanks to Allah.