Q:

Car computer how to connect to car battery and also not drain battery when the car is switched off

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.

A:

I have not measured it myself, but this person claims the pi draws about 110 mA after shutdown, i.e., when the OS has halted and just the red PWR led glows.
Figures regarding the number of amp-hours in a car battery seem to vary quite widely; if we assume 50, then that's 50 / .11 ~= 454.5 hours such a battery should last with an inoperative pi attached.  Of course, if you want to use the battery to start your car, you probably don't to go even half that far (also, draining a lead acid battery excessively shortens its lifespan).
The important part here is that the OS be shutdown.  Otherwise, even when idle  the pi draws at least 300 mA.  
There are people who sell power off switches for the pi; these use a GPIO pin to signal the system to shutdown, wait for confirmation, then cut the power.  Note this also requires a bit of software. If you search online you'll find such switches (they are built specifically for the pi) for ~$15-20.

I do not know if this should be done in code

There has to be some kind of hardware involved to accomplish this.  If you wire the pi so the power is linked to the ignition state (on or off), you still need to signal the pi first so it can cleanly shutdown (if you don't do this, you will eventually run into problems).  If you leave the power on, you need hardware to do the same thing, plus cut the power (as per the switches above).

I am also looking for ways on how to connect to the car battery and use that as my power source

You need a 12v - 5v DC converter, I guess.  These are cheap and widely available.

