I am doing research on creating a car computer with raspberry pi (so I have all the basics down before I start this project) and I am looking on a way to switch the whole device automatically whenever the car is switched off. I have found Android ROMs that do this exact thing but I want to build it from scratch with Raspberry pi. As my car battery is not huge, the device cannot and must not run when the car is switched off unless I explicitly turn it on.
What I want is functionality similar to how the car radio turns off at the exact moment the car is turned off so it does not drain my car battery.
I do not know if this should be done in code or with specific hardware. I am just looking for guidelines on how to proceed.
I am also looking for ways on how to connect to the car battery and use that as my power source.