1

I found this code snippet to programmatically go to the home screen on clicking the back button.

  public void onBackPressed() {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);
    }

What is the purpose of using setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
jenny jenkins
  • 95
  • 1
  • 9
  • 2
    Exactly what the documentation says https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK – tyczj Mar 22 '21 at 20:33
  • Does this answer your question? [FLAG\_ACTIVITY\_NEW\_TASK clarification needed](https://stackoverflow.com/questions/9772927/flag-activity-new-task-clarification-needed) – ADM Mar 23 '21 at 06:30
  • I understand what the use of `FLAG_ACTIVITY_NEW_TASK` is. I just can't seem to comprehend why it is needed here. – jenny jenkins Mar 24 '21 at 16:52

0 Answers0