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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:35:40+00:00 2026-06-13T18:35:40+00:00

The application(target API level must be 7th) has FragmentActivity which analyzes at onCreate the

  • 0

The application(target API level must be 7th) has FragmentActivity which analyzes at onCreate the fragment key passed as an extra.

Now what is needed is to reorder to front the activity that is already created with the given fragment key.

Let’s say the FragmentActivity with different fragment keys are FA1, FA2 and FA3 – each is the same activity Class instance with different fragments.

Now in the stack FA1 > FA2 > FA3 i want to use the intent rather than the back button to get to FA2, by default that gives:

FA1 > FA2 > FA3 > new FA2.

I’d like to get either FA1 > FA3 > FA2 as the FA3 might have some pending operations, FA1 > FA2 is not as good but definitely better than default.

If there were several activities I’d use the FLAG_ACTIVITY_REORDER_TO_FRONT flag for intents, but that does not work for this case.


FA1, FA2, FA3, etc. are all the instances of the same class MyFA, that’s why I’m not able to use the intent flag and the FragmentManager seems to be out of help until there’s a standard global fragments cache.


Milestone (currently working and to be improved) solution One thing I’ve learned today is activity-alias which allowed to make several aliases for the same activity with the different Intent extras used as id’s. Now with the REORDER_TO_FRONT flag it works as I wanted.

Solution feedback The solution has no low-level operations, I like a lot more than digging at the tasks or back-stacks. Now the drawback is that each of such activities needs a separate alias with the hardcoded path, I don’t really like it.

Requirements (bounty is here) Whoever comes with a decent optimization takes 150 300 cookies. Not bad ? Any other solid solution is also highly appreciated.

Currently I have like 10 aliases at application manifest, e.g.

    <activity
        android:name=".activity.FragmentActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />

            <action android:name="com.company.name.intent.FragmentActivity" />
        </intent-filter>
    </activity>

    <activity-alias
        android:name="com.company.name.intent.FragmentActivity.FragmentedOne"
        android:targetActivity=".activity.FragmentActivity" >
        <intent-filter>
            <action android:name="com.company.name.intent.FragmentActivity.FragmentedOne" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="fragment_key_extra"
            android:value="FragmentOne" />
    </activity-alias>
    <activity-alias
        android:name="com.company.name.intent.FragmentActivity.FragmentedTwo"
        android:targetActivity=".activity.FragmentActivity" >
        <intent-filter>
            <action android:name="com.company.name.intent.FragmentActivity.FragmentedTwo" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="fragment_key_extra"
            android:value="FragmentTwo" />
    </activity-alias>

And then the activities are reordered with

Intent intent = new Intent(
"com.company.name.intent.FragmentActivity.FragmentedOne");
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
  • 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-13T18:35:41+00:00Added an answer on June 13, 2026 at 6:35 pm

    Based on your idea of using activity-alias to solve this issue, I wrote a Historian class that will do the following:

    • Scan the Activity list in your package for aliases to your specific Activity.
    • Set up a lookup table that maps each alias to an Intent.
    • Provide a startActivity() and activityDestroyed() methods that will do some bookkeeping so the lookup table can be used to dynamically assign an alias to a running Activity based on the Intent.

    Here’s an example on how to use it:

    • in AndroidManifest.xml

      <activity android:name=".MyFragmentActivity">
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
      </activity>
      <activity-alias android:name=".Alias0" android:targetActivity=".MyFragmentActivity" />
      <activity-alias android:name=".Alias1" android:targetActivity=".MyFragmentActivity" />
      <activity-alias android:name=".Alias2" android:targetActivity=".MyFragmentActivity" />
      <activity-alias android:name=".Alias3" android:targetActivity=".MyFragmentActivity" />
      <activity-alias android:name=".Alias4" android:targetActivity=".MyFragmentActivity" />
      
    • within your Activity class

      public class MyFragmentActivity extends FragmentActivity
              implements Historian.Host {
      
          private Historian<MyFragmentActivity> mHistorian;
      
          // ...
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
      
              mHistorian = new Historian<MyFragmentActivity>(this);
      
              // ...
          }
      
          @Override
          protected void onDestroy() {
              super.onDestroy();
              mHistorian.activityDestroyed(this);
          }
      
          @Override
          public boolean matchIntent(Intent intent0, Intent intent1) {
              if (intent0 == null || intent1 == null) return false;
              final String title0 = intent0.getStringExtra("title");
              final String title1 = intent1.getStringExtra("title");
              return title0.equals(title1);
          }
      
          // ...
      
      }
      

    Instead of starting a new instance of your activity like this:

        Intent intent = new Intent(this, MyFragmentActivity.class);
        intent.putExtra("title", newActivityTitle);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
    

    You do this:

        Intent intent = new Intent(this, MyFragmentActivity.class);
        intent.putExtra("title", newActivityTitle);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mHistorian.startActivity(this, intent);
    

    So you still need to add a few activity-alias into your manifest manually (to be used as a pool) and implement the matchIntent() method in your Activity (to help detect whether two Intents are equal to you) but the rest is handled dynamically by the Historian class.

    I haven’t tested the code exhaustively, but it seems to work fine on some simple tests that I did. The idea is actually very similar to my answer on the other question (just need to use FLAG_ACTIVITY_CLEAR_TOP instead of FLAG_ACTIVITY_REORDER_TO_FRONT there) but using the activity-alias instead of the inner child classes make it much cleaner 🙂

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

Sidebar

Related Questions

I have a console application which has target .NET 2.0 It is very short
I want to use in my application classes from API Level 11. Which in
I've got a project which links to API level 11. When I run this
I have developed an application with Target build as API 4. It supports Normal
I am using target API 16 and minimum API 11 with compliance level of
I have made an application which has been tested on the emulator, some 2.2
For my application, I have a custom implementation of SharedPreferences . In API level
I want to set in project properties build target 2.2 (api level 8) In
Target application is a medium-sized website built to support several hundred to several thousand
When developing an RCP application against a target platform, I ( and others )

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.