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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:32:46+00:00 2026-06-18T23:32:46+00:00

I have a class which is under a test with Robotium, in it’s onPause()

  • 0

I have a class which is under a test with Robotium, in it’s onPause() method I just clear the EditText (I don’t need the data to be preserved after onPause()).

So I have in a class which is under a test:

@Override
protected void onPause() {
    super.onPause();
    mEdtPassword.setText("");
}

and testing method:

public void testOnPauseOnStart() {
        Activity mActivity = getActivity();
        solo.typeText(0, CORRECT_PASSWORD);

        getInstrumentation().callActivityOnPause(mActivity);
    }

But then I got an error:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4746)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:854)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4077)
at android.view.View.invalidate(View.java:10322)
at android.widget.TextView.invalidateRegion(TextView.java:4395)
at android.widget.TextView.invalidateCursor(TextView.java:4338)
at android.widget.TextView.spanChange(TextView.java:7186)
at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:8821)
at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:979)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:688)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
at android.text.Selection.setSelection(Selection.java:76)
at android.text.Selection.setSelection(Selection.java:87)
at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:302)
at android.widget.TextView.setText(TextView.java:3555)
at android.widget.TextView.setText(TextView.java:3425)
at android.widget.EditText.setText(EditText.java:80)
at android.widget.TextView.setText(TextView.java:3400)
at <package>.ui.CheckPasswordActivity.onPause(CheckPasswordActivity.java:182)

If I use solo.setActivityOrientation(Solo.LANDSCAPE) I don’t get this error.

Then if I wrap the mEdtPassword.setText("") with runOnUiThread() everything is fine.

So the questions are:

  1. Why I don’t have this exception when I use solo.setActivityOrientation() but I do when I use getInstrumentation().callActivityOnPause(mActivity), I presume both are doing the same thing.

  2. Shall I wrap things like mEdtPassword.setText("") in onPause() with runOnUiThread somewhere else for some other reasons or I just need it for testing purposes?

  3. Does it mean if I want to have tests of my UI I need to write more code (like running ordinar operations on UI thread) to make it possible to run them?

Thank you very much for clarification.

  • 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-18T23:32:47+00:00Added an answer on June 18, 2026 at 11:32 pm

    Praful is mostly correct although I believe you are unable to use instrumentations methods within a test annotated with @UiThreadTest. This means your best option is in fact to wrap instrumentations method in a runnable that you can post to the main thread. for instance:

    public void callActivityOnPause(final Activity activity){
        getInstrumentation().runOnMainSync(new Runnable() {
                public void run() {
                    activity.onpause();
                }
            });
    }
    

    I havent tried this code, so its probably wrong, just killing time on the train!

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

Sidebar

Related Questions

I have class which have one public method Start , one private method and
I have a jar with main-class which can be executed like: java -jar test.jar
I have a a test class which is named xxxTest.java so the test class
I have a unit test that creates an error condition. Normally, the class under
I have a method under test. Within its call stack, it calls a DAO
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I have class A which extends the Activity class. This class is in package
I have class World which manages creation of object... After creation it calls afterCreation
I have class Employee which is something like this. class Emp { int EmpID;

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.