Union Government
A Speaker or Deputy Speaker vacates office on ceasing to be a member of the House, may resign by writing (to the Deputy Speaker or Speaker respectively), and may be removed by a resolution of the House passed by a majority of all its then members, after at least fourteen days' notice - though the Speaker continues in office until just before the newly-elected House's first meeting, even after a dissolution.
Similar removal rules apply to the Lok Sabha's Speaker and Deputy Speaker as apply to the Rajya Sabha's Chairman and Deputy Chairman, with one important addition: even after the Lok Sabha is dissolved for elections, the outgoing Speaker continues in office until just before the new House's first sitting - ensuring there's always someone formally holding that role.
This is why, even during the gap between one Lok Sabha's dissolution and the next Lok Sabha's first sitting after an election, there is technically still a sitting Speaker (the outgoing one) rather than a total vacancy in that office.