in the MainActivity , I have this code for closing the application :
@Override
public void onBackPressed() {
if (exit){
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
super.onBackPressed();
}else {
exit = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
exit = false;
}
}, 3 * 1000);
}
I should press 2 back button when I want to close the application .
The problem is ,when I close the application, it starts from another activity , mostly from the last activity I've been to .
How can I always start the activity from mainActivity not other activities ?