Override the onStop method of your activity:
@Override public void onStop(){ super.onStop(); finish(); }
But I think it is a bad idea to restart the application every time. It is better to override the onStart method and restart here.
Actually, your application does not start in the background. Android OS saves it in memory or saves the state of your activity on the device (and then you can load it using the savedInstanceState parameter in the savedInstanceState method).
source share