Not recommened but still you can use this. Better go with this solution in case you need to quit the app.
According to me the best solution is finish every activity in your app like below.
step1) maintain a static variable in mainactivity say.
publicstatic isQuit =false;
step2) on click event of an button make this variable to true.
mainactivity.isQuit =true;
step3) And in every activity of your application have onrestart method as below..
@Override
protectedvoid onRestart(){
// TODO Auto-generated method stub
super.onRestart();
if(mainactivity.isQuit)
finish();
}