0

im developing a application where in in my main menu i have 4 buttons.the problem is one of my button(exit button) if i tap on that it intent to my previous activity..pls help me..ive tried to use finish() and system.exit(0) but it don't work..help is really appreciated!

public class MainMenu extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);

    Button btnaniking =(Button) findViewById(R.id.baniking);
    btnaniking.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent("myapp.animalkingdom.ANIKING") );
    }
});
    Button btnwhoami =(Button) findViewById(R.id.bwhoami);
    btnwhoami.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent("myapp.animalkingdom.WHOAMI") );
    }
});
    Button btncredits =(Button) findViewById(R.id.bcredits);
    btncredits.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent("myapp.animalkingdom.CREDITS") );
    }
});
    Button btnexit = (Button) findViewById(R.id.bexit);
    btnexit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
            System.exit(0);
        }
    });
user2079544
  • 29
  • 1
  • 5
  • 4
    Simply remove this button, as it is not necessary on Android. http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238 – CommonsWare Mar 08 '13 at 00:18

1 Answers1

4

Don't break Android's paradigm. It's not up to you to decide when the close the application. Let the user and the OS take care of that.

If, for whatever reason, you really have to do this. You can just call finish(). This will shut down the current activity, leading to an eventual app closure if the activity is the only one on the history stack.

jlindenbaum
  • 1,891
  • 18
  • 28