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.
//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,
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With