AND-401 Exam QuestionsBrowse all questions from this exam

AND-401 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?

Show Answer
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

1 comment
Sign in to comment
MmadiOption: A
Dec 31, 2022

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.