Why does my phone reset every time the battery dies?

A

AC Question

I can turn off my phone, restart my phone and it turns on in the same condition it turned off. But if I let the battery die, i'm screwed. The phone completely resets and I need to set up all my accounts again, set all my preferences, and reorganize my playlists. It's a huge pain in the *** and it happens almost every time the battery dies. Why is my phone doing this and how can I make sure it never happens again?
I have an HTC one m8 and the newest android OS.