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

The Archive Base Latest Questions

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

I must be missing something obvious here: I’m running an instrumentation test case on

  • 0

I must be missing something obvious here:

I’m running an instrumentation test case on a device, also with the help of Robotium. At some point my app under test causes the default e-mail compose activity to fire.

What I’d like to know is: how do I close that activity so to show back again my app activities? That is needed at least for one reason: after current test case completes, the email activity remains in foreground, and this prevents the next test case from running properly.

I tried to send the required back keys to the email activity – with this.sendKeys(KeyEvent.KEYCODE_BACK) or solo.goBack() – but with no luck.

If I run solo.getCurrentActivity() or this.getActivity() I get a reference to the topmost activity within my package, but no way to get a hold of the actual foreground activity. Also, the mentioned sendKeys/goBack go straight to my activity, not the email one.

Same problem arises when my app launches the Play Store main activity.
I realise that the email activity is not part of my package under test, and this might be part of the problem.

So, is there a way to close the email ativity?

Edit
For now I’m sticking to @Joe Malin first suggestion:

In my ViewModel (or Controller), have a private static boolean _productionMode = true;
and have some helper method (better if in some inner helper class) used only during testing:

public void dontLaunchExternalApps()
{
  _productionMode = false;
}

Then in some ViewModel regular method:

if (_productionMode)
{
   launchSomeExternalApp();
}
else
{
   // Do Nothing Or Set Some Internal Flag
}
  • 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-14T23:41:21+00:00Added an answer on June 14, 2026 at 11:41 pm

    There’s no good way to do it. The Android instrumentation framework is really meant to unit test an Android component. Once control passes out of the component, some other framework has to take over.

    Perhaps you can start the initial activity with extended data that tells the Activity to send a stub email Intent instead of the real one. The real problem is not closing the the email Activity, it’s mocking it so that you get back from it what you expect to get back. Unfortunately, mocking is not supported in Android components. The way around that is to delegate most operations to POJO subclasses and then mock them.

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

Sidebar

Related Questions

I think I'm missing something really obvious here... must be... but for some reason
Help me out here; I must be missing something really obvious. I have a
I must be missing something obvious here... I can't get .change() to fire on
Must be missing something really obvious here but how do you change the size
Okay, I know I must be missing something obvious here. Here's the sample code
I must be missing something quite obvious here because something rather strange is happening
I must be missing something obvious here, but I can't seem to get the
OK, I must be missing something obvious here, but can't find an answer anywhere.
I must be missing something obvious here... I found the online documentation for the
I know I must be missing something really obvious here. B.GetInstance().Call() generates the error:

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.