Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to exit android application from exit button? [duplicate]

Tags:

android

Possible Duplicate:
android - exit application code

I am finding the way to exit android application to home screen(android phone).

My code is not completely exit application but it turn to the root activity of application.

Here is my code

//Expression
    Button exit = (Button) findViewById(R.id.exit);
    exit.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            finish();
            System.exit(0);
        }
    });

Can you tell me how to exit application and go to home screen of android phone?

Regards,

like image 471
SopheakVirak Avatar asked May 12 '26 00:05

SopheakVirak


1 Answers

public void AppExit()
{

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

    /*int pid = android.os.Process.myPid();=====> use this if you want to kill your activity. But its not a good one to do.
    android.os.Process.killProcess(pid);*/

}

call this method where you click exit button

like image 178
Ram kiran Pachigolla Avatar answered May 14 '26 13:05

Ram kiran Pachigolla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!