Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:24:42+00:00 2026-06-05T20:24:42+00:00

I have doubt with android backstack , please consider the scenario I have two

  • 0

I have doubt with android backstack , please consider the scenario I have two activities A and B in same app ,

  1. start with A.
  2. from A launch B using FLAG_ACTIVITY_NEW_TASK
  3. from B launch A using FLAG_ACTIVITY_NEW_TASK
  4. press Back button 3 times to return to home screen.

My question is how does the backstack work with this flag , is new task created every time and previous task is pushed to background or activity is created on top of same task.

My doubt is if first one is correct then does back button really remove the activity from top of the stack and if second is correct what is the use of that flag in correct sense.

Thanks in advance.

Regards,
Rohit

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:24:43+00:00Added an answer on June 5, 2026 at 8:24 pm

    First of all, launching B using FLAG_ACTIVITY_NEW_TASK will NOT create a new task unless you have explicitly set android:taskAffinity in the manifest for B. The reason for this is that, by default, all Activities in your application have the same taskAffinity and taskAffinity overrides FLAG_ACTIVITY_NEW_TASK.

    If you have set the taskAffinity of A and/or B so that they are different (or both empty), then it works like this:

    • User launches A from homescreen. You now have one task (let’s call it TaskX)
    • A launches B with FLAG_ACTIVITY_NEW_TASK. You now have two tasks (let’s call the new task TaskY). TaskX is pushed to the background and TaskY is in the foreground.
    • B launches A with FLAG_ACTIVITY_NEW_TASK. You still only have two tasks. B (in TaskY) launched A which created a new instance of A and put it in TaskX because the first instance of A has the same taskAffinity as the second instance of A). This also causes TaskX to come to the foreground and TaskY to go to the background.
    • Press “back”. The second instance of A is removed from the stack and you go back to the first instance of A in TaskX. Pressing the “back” key goes back within the current task.
    • Press “back”. The first instance of A is removed from the stack. TaskX is now empty as it has no activities in it. The previous task (TaskY) is brought to the foreground and B is resumed.
    • Press “back”. The instance of B is removed from the stack. TaskY is now empty and the home screen is shown.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a doubt in listview android. I am getting 3 dynamic values from
I have a small doubt regarding network connection procedure in Android. My scenario is
I have to connect to my database from android appication. My doubt is how
I have a doubt regarding JNI function calls made from Android. Do they run
i have one doubt,i have created new project in eclipse with android 2.3.1 and
i'm new at Android world, and i have a doubt, is there any method
I have doubt in the following scenario Scenario: A process or program starts with
I have a doubt in android ImageView . I'm making a sample application to
If you own Android phone you are no doubt have noticed how in the
I am new to android, I have a small doubt regarding how to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.