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 8526181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:11:59+00:00 2026-06-11T08:11:59+00:00

I have a special navigation in my application and i’m wondering how can I

  • 0

I have a special navigation in my application and i’m wondering how can I set it properly.

An activity H is the homescreen of my application. From this activity, we can launch activities A, B, C, and D. From activity A we can launch A’ that launch A”, from activity B we can launch B’, that launch B”, etc.

The problem is that from ANY activity, we can go to the activity H, A, B, C or D. But, when the user launch A->A’->A”->C, and then go back on A, he has to be redirected to A”. Moreover, still with this example, if the user press back on A”, he has to be redirected to A’ and not to C. If he press back again he has to be redirected to A, and back again should redirect him to the H (home screen) activity, not to C !

Finally, when the user press back from H, and only at this moment, the application (and all tasks if the solution choosen is to create separated tasks) should shutdown.

Other example : H -> A -> B -> H -> back -> end of application

How can I achieve this ?
I have thinked to use task like that :

<!-- A-->
<activity
    android:name=".A"
    android:excludeFromRecents="true"
    android:taskAffinity=".A"
    android:label="@string/my_A_label">
</activity>
<activity
    android:name=".A'"
    android:taskAffinity=".A"
    android:label="@string/my_A'_label">
</activity>
<activity
    android:name=".A''"
    android:taskAffinity=".A"
    android:label="@string/my_A''_label">
</activity>


<!-- B-->
<activity
    android:name=".B"
    android:excludeFromRecents="true"
    android:taskAffinity=".B"
    android:label="@string/my_B_label">
</activity>
<activity
    android:name=".B'"
    android:taskAffinity=".B"
    android:label="@string/my_B'_label">
</activity>
<activity
    android:name=".B''"
    android:taskAffinity=".B"
    android:label="@string/my_B''_label">
</activity>

...

As you can see, I have created tasks for each main page : A, B, C, D.
I don’t know if it’s the good thing to do because, for example, with task, the user can see all theses activities on long press on his home button with the “last task” option, and I don’t want have this behaviour. For that, activities A, B, C, D (root screen of each task) have the attribute android:excludeFromRecents=”true”. But now, another problem : when the user click on his home button, and go back to my application, he go back to home screen, not to the last activity launched…

Moreover, my second example is not respected.

Have you an idea to resolve all these problems ?

P.S : Please don’t tell me to change my navigation system 🙂

EDIT : here a flow chart that represents the back comportment needed. This comportment seems to be normal. What is differring in my case doesn’t appear on this chart. Indeed, only back button is represented. Each context – represented by a different color – can switch to another context, without override the back comportment described here.

back comportment

EDIT2 : Thanks to advices of David Wasser, I have implemented two classes that exactly do the comportment that I have described, without using of android tasks. Thanks to JoxTraex for his help too 🙂 Here what I’ve done : my activities A,B,C,D extend RootActivity, the other except H extend CustomNavigationActivity.

RootActivity :

import android.content.Intent;

public abstract class RootActivity extends CustomNavigationActivity{

@Override
public void onBackPressed(){

    Intent intent = new Intent(this, HomeScreen.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

}

}

CustomNavigationActivity :

import android.content.Intent;

public abstract class CustomNavigationActivity extends Activity{

private int actualRequestCode;
private int menuRequestCode = -1;

@Override
protected void onResume(){

    if (getIntent().hasExtra("childLaunched")){

        Intent intent = new Intent(this, (Class<?>) getIntent().getExtras().get("childLaunched"));
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);

    }

    super.onResume();       

}

@Override
public void startActivity (Intent intent) {

    this.startActivityForResult(intent, 0);

}

@Override
public void startActivityForResult(Intent intent, int requestCode){

    Class<?> targetClass = null;
    this.actualRequestCode = requestCode;

    if (this.actualRequestCode == this.menuRequestCode){
        this.menuRequestCode -= 1;
    }

    try {
        if (intent.getComponent() != null){
            targetClass = Class.forName(intent.getComponent().getClassName());
        }
    }
    catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    if (targetClass == null){
        super.startActivityForResult(intent, this.actualRequestCode);
    }
    else if (!targetClass.equals(Menu.class)){
        getIntent().putExtra("childLaunched", targetClass);
        super.startActivityForResult(intent, this.actualRequestCode);
    }
    else{
        super.startActivityForResult(intent, this.menuRequestCode);     
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){

    if (requestCode == this.actualRequestCode){
        getIntent().removeExtra("childLaunched");
    }

}

}
  • 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-11T08:12:01+00:00Added an answer on June 11, 2026 at 8:12 am

    You definitely do not want different tasks for this. It will completely mess up your navigation if the user leaves the app (press HOME, answer a call, etc.) and wants to come back. You can only use separate tasks if you have a unique icon and/or name for the activity that is at the root of each task and if the tasks can all run in parallel. Only then will you not confuse the user. It seems that you don’t want want.

    Have a look at my answer to Activities Stack Issue

    It isn’t exactly what you want but you might get some ideas from this answer. If you still have questions after looking at this just add comments and I can help you more.

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

Sidebar

Related Questions

Does ** have any special meaning in C? Like this: static intparse_one (int argc,
I have a webpage at http://www.optiekmeulemeester.be/normal with sliding navigation. This happens with the following
Does the iPhone browser have special events that I can hook into with Javascript?
Some Google search results have special "navigation" items right underneath their descriptions. Sometimes it
Alright, I can't find this option anywhere. I'm generating Zend Navigation through the database
I have an application on which a user can create multiple profiles of three
I have a jQuery autocomplete set up, for which I have a few special
how can I add special characters in a UILabel in objective-c? Like I have
Is it possible to have special characters like åäö in the key? If i
I'm trying to query by iteration but our iteration names have special characters (e.g.

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.