(The acceptance of) all actions are based on the intentions (with which the actions were carried out).
Hazrat Shaikh Moulana Muhammad Zakariyya (rahmatullahi ‘alaih) once quoted the above Hadith and thereafter explained:
Whatever good deeds you carry out, do them with the sole intention of pleasing Allah Ta’ala. If a person performs salaah for show, so that people may regard him to be a pious person, then the salaah performed will be rejected and flung onto his face.
The author of Mazaahir-e-Haq has written in the commentary of this Hadith that if a person enters the musjid, performs two rakaats of salaah, makes the intention of nafl i’tikaaf, intends to meet the pious servants of Allah Ta’ala and makes other similar intentions of righteous works, he will receive abundant reward from Allah Ta’ala for the good intentions that he makes (and if he performs these righteous actions, he will receive a separate reward for carrying them out). (Suhbat Baa Awliyaa pg. 95-96)