The sayings of the Prophet (saws) concerning dissimulation and the seeking of praise and honour had made the Companions so greatly afraid that some of them felt that if people started admiring anyone for a good deed, and his devoutness and well-doing began to be talked about, the deed might not find acceptance with God as he had been recompensed already, in this world, in the form of affection and admiration. It was as a result of this fear and anxiety that the enquiry was made. The Prophet replied that there was nothing wrong if a person was held in high esteem owing to his virtue and good-doing. On the contrary, it should be taken as an indication of his worthiness, in the sight of God, and a ready recompense, in the present existence, and in advance of the real reward that awaited him in the Hereafter.
In the same way, once, as Hazrat Abu Hurairah was offering up Salah, someone chanced to come and see him in that state. The celebrated Companion tells that he felt pleased at being seen while engaged in a virtuous act like Salah. He narrated it to the holy Apostle so that if his reaction, too, was a form of Riya, he might repent for it and seek the forgiveness of the Lord. But the Prophet assured him that it was not so, and he will be rewarded both for doing a good deed in private and in public.
We, thus, learn from it that if a virtuous act is performed for the sake of God and without the intention of being seen during it, but the others come to know about it, and the person who does so feels happy over it, it will not be opposed to single-minded devotion. Moreover if anyone does a virtuous deed in the presence of others with the idea that they learnt about it and tried to emulate his example, it would not be hypocrisy. In fact, he will be rewarded for the preaching and propagation of Faith.
As many Traditions show, the holy Prophet had the same purpose, also, in the mind while performing an act on a number of occasions.