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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:15:57+00:00 2026-05-28T05:15:57+00:00

I am trying to test drive an application feature using Robotium. One of the

  • 0

I am trying to test drive an application feature using Robotium. One of the features is that when my initial activity is launched from a view on top of the activity stack it should clear the top of the stack and reuse the existing Activity i.g.(“MainActivity”).

Flow:

FirstScreen -> LoginActivityScreen -> RegistrationScreen -> FirstScreen

The solution is simple enough:

   Intent intent = new Intent(getBaseContext(), FirstScreen.class);
   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   startActivity(intent);

By setting the flag Intent.FLAG_ACTIVITY_CLEAR_TOP puts FirstScreen back on the top of my application stack.

The Test I am trying to write is to confirm that when the Hardware Back Button is pressed then the app is gone and the native Home(Launcher) application is the current Activity.

My Instrumentation TestCase:

    @Smoke
    public void testshouldBeOnLauncherHomeScreen() {
        // Monitor the Home (Launcher) Activity being Launched
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.MAIN");
        filter.addCategory("android.intent.category.HOME");
        ActivityMonitor monitor = getInstrumentation().addMonitor(filter, null, false);

        // go back to the launcher home
        robotium.goBack();

        assertEquals(1, monitor.getHits());
    }

I would prefer to assert that the activity of the Launcher app is the current activity. Any ideas or suggestions would be much appreciated.

  • 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-28T05:15:58+00:00Added an answer on May 28, 2026 at 5:15 am

    I have was able to solve this using ActivityUnitTestCase rather than InstrumentationTestCase2. I trust the android OS to bring my FirstScreen to the top by adding the flag. Validating that the flag is set when issuing the intent to start my first screen is enough to give me confidence that my code is doing what I expect.

        Public void testThatStartedIntentHasClearTopFlag() {
            Activity activity startActivity(new Intent(), null, null);
            activity.findViewById(R.id.button).performClick();
            Intent intent = getStartedActivityIntent();
            assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TOP, intent.getFlags());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to test-drive software that launches external processes that
I am trying to test that a particular method throws an expected exception from
I am trying to use test-driven development for an application that has to read
I'm trying to test-drive some Scala code using Specs2 and Mockito. I'm relatively new
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
Im trying to test my successfully creates a new user after login (using authlogic).
I am trying to test the likelihood that a particular clustering of data has
I am trying to test a class that manages data access in the database
I'm trying to connect to a MySQL database using my ASP.NET Web Forms Application.
I'm trying to connect my application with an Oracle database using NHIBERNATE 3.1.0.4000 version

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.