i have a navigation drawer which should close on backpress this works perfectly but when the navigation drawer closes and there is a second time back button press the app closes instead of going to home screen
here is the code i am trying
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if(drawerLayout.isDrawerOpen(Gravity.LEFT)){
drawerLayout.closeDrawer(Gravity.LEFT);
}else{
//super.onBackPressed();
Intent mainActivity = new Intent(Intent.ACTION_MAIN);
mainActivity.addCategory(Intent.CATEGORY_HOME);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mainActivity);
}
how can we close the navigation drawer then go directly to home screen/ main activity
i donot wan to use
Intent i = new Intent(AccountActivity.this, HomeActivity.class);
startActivity(i);