1. The electronic contacts under the on/off switch can sometimes get dirty and need cleaning.
The camera can be disassembled and the contacts under the switch can then be cleaned using contact cleaner or rubbing alcohol.
2. If the lens mechanism is jammed by dirt or the on/off button is working intermittently, then this can cause the lens to cycle in and out continuously.