Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to exit app on button click . ??
Posted

You should read all of the comments on the thread found at the link below.

How to quit android application programmatically[^]
 
Share this answer
 
Comments
Joezer BH 8-Sep-13 5:31am    
5ed!
Just use this code for your button:
Java
exitButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        finish();
        System.exit(0);
    }
});

Though it is not a good idea to use an exit button on an Android app. Let the OS decide when to kill your Activity. I should recommend, learn about the Android Activity lifecycle first and then implement any necessary callbacks.
 
Share this answer
 
v3
Comments
Joezer BH 8-Sep-13 5:31am    
5ed!
ridoy 8-Sep-13 5:49am    
thank you,:)
Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:

Java
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);


reference
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900