Answered by Shaykh Faraz Rabbani
How much movement invalidates prayer?

Walaikum assalam,
1. Excessive action invalidates the prayer.
2. Fidgeting (`abath, which is repeated unnecessary slight actions) is prohibitively disliked.
3. Unnecessary slight action is somewhat disliked (makruh tanzihan).
4. Slight actions done with a reasonable excuse or for the benefit of the prayer are excused, though one should be careful to keep it to the minimal extent possible.
What is excessive action?
Excessive action is defined, according to the soundest position, as being action that would lead an onlooker from a distance, with no prior knowledge that the person is praying, be certain that the person is not praying. When in doubt, it is not excessive action and does not invalidate the prayer. Usually, three uninterrupted major movements would be considered excessive. [Based from Ibn Abidin’s Radd al-Muhtar, `Ala’ al-Din Abidin’s Gifts of Guidance: Al-Hadiyya al-`Ala’iyya]
As such, slight movements to turn off one’s cell phone would be allowed. In fact, this would be the best thing to do, for the benefit of one’s own prayer and the prayer of others. However, one should make it a point of turning off the cell phone before entering the mosque, or leaving it behind.
And Allah knows best.
Wassalam,