On pressing the back button , I'm trying to exit the application from activity.But the problem is after pressing the back key refreshing the same activity 2 to 3 times and goes to Login activity and does not exit the application.Can someone help for solve the issue .
Here is how I have to tried to exit the application.
@Override
public void onBackPressed() {
super.onBackPressed();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("LISTVIEW_EVENT_ONE", false);
editor.putBoolean("LISTVIEW_EVENT_TWO", false);
editor.commit();
this.finish();
//Intent startMain = new Intent(Intent.ACTION_MAIN);
//startMain.addCategory(Intent.CATEGORY_HOME);
//startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
/*Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);*/
/* Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);*/
}