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

  • SEARCH
  • Home
  • 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 7837219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:32:07+00:00 2026-06-02T14:32:07+00:00

is there a case when FLAG_ACTIVITY_NEW_TASK is ignored? From a service I start an

  • 0

is there a case when FLAG_ACTIVITY_NEW_TASK is ignored? From a service I start an activity with an intent that sets that flag and when the main activity is in the background I was expecting to see the new activity in a new task and so I was expecting to see the application in the background again when I close the new activity.
It does not happen and the main activity is shown.

Just for testing I tried to set the main activity as singleInstance and in that case it works. I do not want to set the main activity as singleInstance though.

Do you know when this can happen?

I should add that I see this behaviour on all the devices so it looks like it is the way it should work and not a device specific issue.

  • 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-02T14:32:10+00:00Added an answer on June 2, 2026 at 2:32 pm

    I fixed it setting a different affinity for the second activity. The problem is that the documentation about the FLAG_ACTIVITY_NEW_TASK flag states:

    If set, this activity will become the start of a new task on this history stack

    but this is misleading because it sounds like the framework will always create a new task, and this is not true when the activity is started from a service.

    This is the documentation about the taskaffinity attribute of an activity:

    android:taskAffinity
    The task that the activity has an affinity for. Activities with the same affinity conceptually belong to the same task (to the same “application” from the user’s perspective). The affinity of a task is determined by the affinity of its root activity.
    The affinity determines two things — the task that the activity is re-parented to (see the allowTaskReparenting attribute) and the task that will house the activity when it is launched with the FLAG_ACTIVITY_NEW_TASK flag.

    So what happens is that a new task is started if you call the startActivity from an activity but if you start it from a service, the framework will attach the activity to a task with the same affinity if any exists with the top activity that is not a singleInstance

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case: There's a class called Template and with that
Is there any way to do the following in HQL: SELECT case when flag
There is the TCP URG flag that signa part of the TCP message as
The case: There is a .net application calling unmanaged C code. Used method for
Is there a case when IsChecked property on WPF CheckBox null ? I guess
Is there a case-insensitive variant of the Bob Jenkins hash function? Generics.Defaults.BobJenkinsHash provides a
Is there a case of ... or context where cat file | ... behaves
First I'll lay out what I'm trying to achieve in case there's a different
we are experiencing a few problems with the IDisposable pattern. In this case there
Is there ever a case where a comparison ( equals() ) between two floating

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.