I disagree with the answer above. If you have an exit option in your menu, then ideally you need the following, as not every user will think of pressing the home key (basically, each activity detects that exit has been chosen, and then sends a result telling the next activity to close and then passes the result on again, and again, until they're all closed:-
Use the code below to call each new intent (e.g. when A starts B. Note the startActivityForResult).
Intent mainIntent = new Intent(FromThisClassName.this,NewClass.class);
startActivityForResult(mainIntent, 2); // change the number for each activity/intent
Then, for each intent, add the following code:-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("CHECK","RequestCode = "+requestCode+" ResultCode = "+resultCode+" Intent Data = "+data);
if (requestCode == 2){
if(resultCode == 5){ // 5 = our exit all code.
this.setResult(5);
finish(); // Exit press detected. Quit now.
}
}