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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:21:29+00:00 2026-06-08T20:21:29+00:00

I am writing an Android app with ActionBar enabled. In my case I use

  • 0

I am writing an Android app with ActionBar enabled. In my case I use ActionBarSherlock to provide compatibility, but I think it doesn’t matter in this case.

I have an Up button displaying at the left of ActionBar in my Activity. It appears after a call to setHomeAsUpEnabled(true); and it leads to the HomeActivity.

I want to write a test case which checks that Up button press leads to that HomeActivity.
I am using Robotium to write tests on UI side so I can check the class of the current Activity by following assertion solo.assertCurrentActivity(HomeActivity.class);
But I have not found a way to invoke a press on an Up button.

I’ve tried solo.clickOnView(solo.getView(android.R.id.home)) and getInstrumentation().invokeMenuActionSync(solo.getCurrentActivity(), android.R.id.home, 0); but none of them works.

Any help would be 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-06-08T20:21:31+00:00Added an answer on June 8, 2026 at 8:21 pm

    Found a workaround myself, so posting it here in case anybody will need this.
    This code worked for me:

    public static void clickOnUpActionBarButton(Activity activity) {
            ActionMenuItem logoNavItem = new ActionMenuItem(activity, 0, android.R.id.home, 0, 0, "");
            ActionBarSherlockCompat absc = (ActionBarSherlockCompat) UiTestUtils.invokePrivateMethodWithoutParameters(
                    SherlockFragmentActivity.class, "getSherlock", activity);
            absc.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, logoNavItem);
        }
    

    First you need to obtain ActionBarSherlockCompat object by calling getSherlock() on SherlockFragmentActivity. This method is protected, so I used Reflection API to call it:

    public static Object invokePrivateMethodWithoutParameters(Class<?> clazz, String methodName, Object receiver) {
            Method method = null;
            try {
                method = clazz.getDeclaredMethod(methodName, (Class<?>[]) null);
            } catch (NoSuchMethodException e) {
                Log.e(TAG, e.getClass().getName() + ": " + methodName);
            }
    
            if (method != null) {
                method.setAccessible(true);
    
                try {
                    return method.invoke(receiver, (Object[]) null);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
    
            return null;
        }
    

    You need to pass solo.getCurrentActivity() to my clickOnUpActionBarButton(Activity activity) method and Up button will be pressed.

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

Sidebar

Related Questions

I'm writing my first android app (I'm a noob at android, but decent at
I'm writing an android app where I need to use AES. Is it better
I'm writing an Android app which will be making use of the cloud-2-device messaging
I was writing an Android app for Android SDK 2.3.3 but then I was
I'm writing an android app that has a standard activity, but also needs to
I'm writing an android app that has a standard activity, but also needs to
I'm writing an Android app that I want to use in conjunction with a
While writing an Android App, when I use TextView in different class(MyClass) other than
I am writing an Android App where I am playing video using VideoView,but the
I'm writing an Android App and I'm trying to choose which compatibility library to

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.