I am not sure I understand what you are asking. Are you saying that the phone turns off and on when the battery is in? Or when it is being put in? When putting it in (or taking it out) it should not be on.
If the phone is turning on and off while the battery is in, it could be a few things. Have you checked to make sure the batteries connections are clear of anything (lint, dirt, etc.), that nothing in there is bent and that the battery is in snugly? If it isn't, or anything in there is damaged/bent, then that could cause the device to restart over and over.
Now if it turns on fine, and the battery isn't loose and nothing is bent in there, but continues to restart, then you may have an app or software bug. I would suggest then that...