Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Why use FLAG_ACTIVITY_CLEAR_TASK when using FLAG_ACTIVITY_NEW_TASK (from Navigation with back and Up video)
I've just seen the Navigation with back and Up video and I don't understand why one need to add FLAG_ACTIVITY_CLEAR_TASK and not just using the FLAG_ACTIVITY_NEW_TASK only? after all when using a new task the starting activity is the new root the the new q....
Thank u in advace
FLAG_ACTIVITY_CLEAR_TASK will cause any existing task that would be associated with the activity to be cleared before the activity is started. This way, when you load that
FLAG_ACTIVITY_NEW_TASK, and you hit the back button, you won't end up back at a login or sign up screen. That'd be a little awkward for our users if they were already logged in and hit it by accident.
Think of it as a stack of papers. Log in on top, main activity on the bottom. When we call
FLAG_ACTIVITY_CLEAR_TASK, we remove the log in paper. Now we're looking at the main activity paper. But if we turn the page back, we don't see the log in paper! :)
If you'd like, you can read more about it under the Intent section of the Android Developer references!