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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:07:10+00:00 2026-05-31T23:07:10+00:00

I would like to have this behavior in a task history stack: First task

  • 0

I would like to have this behavior in a task history stack:

  • First task history stack is:
    • Scenario 1.1: activity Main -> activity A -> activity B
  • Next, activity B launches activity A, same instance
    • Scenario 1.2: Main -> A -> B -> A (duplicate)

This way, if user presses back button, he goes back to B, and pressing back button again goes back to A (always same instance of A).

Using intent flag “FLAG_ACTIVITY_REORDER_TO_FRONT” I have achieved the behavior:

  • First:
    • Scenario 2.1: Main -> A -> B
  • B launches A
    • Scenario 2.2: Main -> B -> A

So same instance of A is actually brought to front, but after leaving B with back button, A is no longer between B and Main, so Main is shown.

  1. Is there any flag/activity-attribute or so, that can simplify achieving this behavior?
  2. Or do I need to handle “back button presses” on activity A?
    • If so, assuming I am on scenario 2.2, how can I reorder A (after detecting back-button) to put it in between Main and B?
  3. Any other comments/suggestions will be appreciated.

Thank you!

  • 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-05-31T23:07:11+00:00Added an answer on May 31, 2026 at 11:07 pm

    I think that your desired scenario is normally impossible.Because of Tasks and Back Stack says:

    When the user presses the Back button, the current activity is popped
    from the top of the stack (the activity is destroyed)

    So if your task be A -> B -> A (duplicate) and user presses back button, he goes back to B and A is destroyed and he can not go back to A.
    I wrote tree activities A,A1,A2 that have this behavior:
    Main -> A -> A1 -> A2 -> A1(duplicated)
    Next when user presses BACK in A2:
    A1 -> A2 -> A1(same) -> A -> Main
    This is their codes:
    Activity A is:

    package t.t;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class TaskTestActivity extends Activity {
        Button btn; 
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main0);
            btn = (Button) findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i = new Intent(TaskTestActivity.this, TaskTestActivity1.class);
                    i.putExtra("loader", "A");
                    TaskTestActivity.this.startActivity(i);
                }
            });
        }
    }    
    

    Activity A1 is:

    package t.t;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.inputmethod.InputMethodManager;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class TaskTestActivity1 extends Activity {
        Button btn;
        String str = "";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main1);
            btn = (Button) findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i = new Intent(TaskTestActivity1.this, TaskTestActivity2.class);
                    i.putExtra("loader", "A1");
                    TaskTestActivity1.this.startActivity(i);
                }
            });
        }
        @Override
        public void onBackPressed() {
            System.out.println(str);
            if(str.equals("ali")){
                Intent i = new Intent(this,TaskTestActivity2.class);
                this.startActivity(i);
                str = "";
                System.out.println("BACK");
            }else{
                Intent i = new Intent(this,TaskTestActivity.class);
                this.startActivity(i);
                str = "";
                System.out.println("BACK1");
            }
    
        }
        @Override
        protected void onNewIntent(Intent intent) {
            // TODO Auto-generated method stub
            super.onNewIntent(intent);
            str = "ali";
        }
    
    }   
    

    Activity A2 is:

    package t.t;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.inputmethod.InputMethodManager;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class TaskTestActivity2 extends Activity {
        Button btn;
        int i = 0;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            btn = (Button) findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i = new Intent(TaskTestActivity2.this,
                            TaskTestActivity1.class);
                    i.putExtra("loader", "A2");
                    TaskTestActivity2.this.startActivity(i);
                }
            });
    
        }
    }    
    

    Note that I override onBackPressed() in activity A1 and you would to detect you want to back to A2 or A,So I Add an extra to intent and override onNewIntent(Intent intent) in A1.My project manifest is:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="t.t"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk android:minSdkVersion="15" />
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" android:hardwareAccelerated="true">
            <activity
                android:label="A"
                android:launchMode="standard"
                android:name=".TaskTestActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:label="A2"
                android:launchMode="singleInstance"
                android:name=".TaskTestActivity2" >
            </activity>
            <activity android:name="TaskTestActivity1" android:launchMode="singleTask" android:label="A1"></activity>
        </application>
    
    </manifest>   
    

    Pay attention to “singleInstance” and “singleTask” properties in Activities elements.Finally you can use this layouts for your activities to sure A1 is duplicated:

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A2"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <RatingBar
            android:id="@+id/ratingBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    main1.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A1"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    
    
    
    
        <RatingBar
            android:id="@+id/ratingBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    main0.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario where I would like to redirect my domains using the
I have this website iloveforwards.com created using drupal. I would like to have a
I would like to have declaration like this: void Date::get_days_name(const Date& = this) which
I have this piece of logic I would like to implement as a trigger,
I have this table structure and would like to map it using Fluent Hibernate
I have this sample string where I would like to replace the star with
I have this source code from 2001 that I would like to compile. It
I have this dilemma many times - and I would like one time and
I have this container div whose width I would like to set according to
This sounds like it would be a simple task, but I'm running into some

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.