I can't see how an Android device can have that behaviour but if it does, and if it has a removeable battery, taking that out should shut it down quickly enough.
When you replace the battery and the back panel, press the Volume Up button and hold it down while you press the Power button.
When you see the menu, use the volume up and down buttons to scroll down the menu and the power button to make a selection. First off, select Wipe Caché. That might clear the problem but if it doesn't go through the procedure again and this time, choose Factory Reset.
You will lose all your personal files - music, photos, etc but you will have a working device. If those data are important to you, conenct the device to a PC using a...