[Android] Create button to close apps android – Button close app Android

To create this button, you'll first need 1 Button was designed by XLM.
At * .java file do the following:

Button btFinish = (Button) findViewById(R.id.finish);
btFinish.setOnClickListener(new OnClickListener() {

	@Override
	public void onClick(View v) {
		//Khoi tao lai Activity main
		Intent intent = new Intent(getApplicationContext(), Main.class);
		startActivity(intent);
		
		// Tao su kien ket thuc app
		Intent startMain = new Intent(Intent.ACTION_MAIN);
		startMain.addCategory(Intent.CATEGORY_HOME);
		startActivity(startMain);
		finish();
    }
});

Before creating the event finish my app reset main activity because it can close the application when we are in a different activity, when restarting the application will run right into the activity that is not our main activity.