1. When a user exits an application, your Application, Activity, and Fragment classes will go through their general lifecycle calls (Activity | Android Developers), so if you want to do anything at these moments, just implement those methods.
As for keeping a user logged in, you'll need to...