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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:56:41+00:00 2026-06-14T10:56:41+00:00

In my app, I want to programmatically bring the most recently used third party

  • 0

In my app, I want to programmatically bring the most recently used third party Activity to the front. After looking at other answers here, I’ve tried relaunching the activity using the baseIntent returned from a list of recent tasks, but that does not seem to bring the activity to the front over whatever else is going on.

My end goal is to create an app that replaces the incoming call screen with a small overlay so the user is not pulled completely out of whatever app they are using when they get a call. I’ve found you can’t replace the default incoming call screen (if this is not true, please let me know as I’d rather do that instead) so as a workaround, I am trying to call the most recently used app to the front of the screen (to overlay the incoming call screen) and then display my overlay on top of that.

Here’s the code I am using (The activity is launched from a broadcast receiver)

public class BringMRUAppToFront extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        ActivityManager activityManager = (ActivityManager) getSystemService("activity");
        List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(1, ActivityManager.RECENT_WITH_EXCLUDED);
        if(recentTasks.size() > 2) {
            RecentTaskInfo recentTask = recentTasks.get(2);
            Intent testIntent = recentTask.baseIntent;
            Log.i("MyApp", "Recent task - " + recentTask.baseIntent.getComponent().getPackageName());

            testIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
            startActivity(testIntent);
        }
        finish();
    }
}

Is there a reliable way to bring any third party activity to the front? The activity is guaranteed to be in memory (if one is not in memory, then I would just display the home screen), so there shouldn’t be an issue there. I also don’t believe it would be a security issue in this case as it would just be displaying an app that was visible right before the phone rang – though I do understand that opening this up in general in the SDK could pose a risk…still hoping it is possible.

EDIT: Modified the code slightly to reflect what I’m doing. The desired task will almost always be the 3rd task in the list – first is the current task and second is the task of the ringing phone. I am able to call the task to the front, but it is not always in the same state (going to the browser’s page instead of the settings screen in the browser, for example). How does the recent tasks list do this?

  • 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-14T10:56:43+00:00Added an answer on June 14, 2026 at 10:56 am

    Figured it out by looking at the Android source code – this is exactly what the Recent Tasks screen does, both pre- and post-Honeycomb:

    RecentTaskInfo recentTask = recentTasks.get(1); // task 0 is current task
    // maintains state more accurately - only available in API 11+ (3.0/Honeycomb+)
    if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        am.moveTaskToFront(recentTask.id, ActivityManager.MOVE_TASK_WITH_HOME);
    } else { // API 10 and below (Gingerbread on down)
        Intent restartTaskIntent = new Intent(recentTask.baseIntent);
        if (restartTaskIntent != null) {
            restartTaskIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
            try {
                startActivity(restartTaskIntent);
            } catch (ActivityNotFoundException e) {
                Log.w("MyApp", "Unable to launch recent task", e);
            }
        }
    }
    

    Permission android.permission.REORDER_TASKS is necessary for this to work correctly.

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

Sidebar

Related Questions

I am writing an app in C# 3.5 in WPF. I want to programmatically
How to get all system font familymane by programmatically in iPhone app i want
I'm developing an iphone app and want to have the option to programmatically change
I want to write a console or Click Once WinForms app that will programmatically
My iOS 4/5/6 app is meant to be used briefly. I want the user
For example, the users of our app want to search products by entering a
In this app I want that as I click on button the data from
In my app,I want to display some information in the middle of the screen
In my WebView app I want to have a custom onReceivedError screen. Instead I
In my app I want the xml to be created dynamically because depending on

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.