Exam AND-401 All QuestionsBrowse all questions from this exam
Question 90

Consider the following code:

Intent i = new Intent(this, MainActivity.class);

i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity(i);

What best explains the code above?

    Correct Answer: A

    The code is using the FLAG_ACTIVITY_CLEAR_TOP flag with the Intent. This means that if the activity being launched is already running in the current task, instead of launching a new instance of that activity, all the other activities present on top of it in the stack will be closed. The existing instance of that activity will then receive the new Intent.

Discussion
MmadiOption: A

A. The activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.