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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:46:03+00:00 2026-06-15T12:46:03+00:00

I am developing simple application with only two activities. Activity C configures application Activity

  • 0

I am developing simple application with only two activities.

  • Activity C configures application
  • Activity A for interaction with user when some event occur

It is not possible for user to navigate from the one to the other – this is why I call them independent activities. Further more activity A is being invoked only form event, there is no way for user to do it manually.

Problem. Let’s assume that application is properly configured. Some event occurs in the system, so application A is being shown to the user. The user interact with it and activity goes to background. Then the user decides to launch configuration activity C. Activity C is shown to the user. The user uses back button to “close” activity, but instead of android launcher or desktop the user is being shown activity A (taken from history).

Similar scenario might happen the other way. C is being used by user, then taken to background. Some event shows activity A and user using back button goes to C instead of closing activity A.

I have solved the problem, but the solution is pretty dirty. Is there any clean or standard way of solving such problem?

Part of my solution includes what was suggested in one answer:

snippet from AndroidManifest.xml:

<activity
  android:name=".C"
  android:clearTaskOnLaunch="true"
  android:excludeFromRecents="false"
  android:launchMode="singleTask"
  ...
 >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
<activity
  android:exported="false"
  android:name=".A"
  android:excludeFromRecents="true"
  android:noHistory="true"
  android:launchMode="singleInstance"
  android:clearTaskOnLaunch="true"
  ....
>
</activity>

snippet from activity A:

public boolean onKeyUp(final int p_keyCode, final KeyEvent p_event) {
    switch(p_keyCode) {
        case KeyEvent.KEYCODE_ENDCALL:
        case KeyEvent.KEYCODE_HOME:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_POWER:
            this.finish();
            break;
        ....
    }
    return super.onKeyUp(p_keyCode, p_event);
}

snipped from event handler:

public class H extends BroadcastReceiver {
...
  Intent intent = new Intent(p_context, A.class);
  intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
  intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  p_context.startActivity(intent);
...
}

It works for my application. However I want application (activity C) to appear in Recent application. But once activity A is invoked application is removed from Recent.

  • 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-15T12:46:04+00:00Added an answer on June 15, 2026 at 12:46 pm

    I don’t know if this is the cleanest way to do this, but you can override the void onBackPressed() activity method. This way you can mannually move your activity to the background, like this, and prevent the previous activity from popping in:

    public void onBackPressed () {
        moveTaskToBack (true);
    }
    

    Edit: Turns out there’s a better way to do this:

    Open your AndroidManifest.xml, and inside each declaration put the following: `android:noHistory=”true”“. Doing so will tell Android that your activity does not leave a history, and therefore, when the user hits back Android will quit the application, since there’s no other activity for it to return to.

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

Sidebar

Related Questions

I am developing a small, internal-use only web application. Given its simple nature and
I'm developing a simple application that fetches some data from wowarmory.com. What I need
I am developing a Windows mobile application. How can I show only two columns
I'm developing a simple application to manage the operational part of a business using
I am developing a simple application which has to send an SMS message from
I'm developing a simple Android application that would have an action bar on the
I am developing a simple pyramid application where I am using JQuery to do
I am developing a simple blog application to teach myself C# and asp .net
I am developing a simple WPF Application that requires a database. My question is,
I'm developing a simple web application where in I need to display number a

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.