RobotiumTech / robotium

Android UI Testing
http://www.robotium.org
Apache License 2.0
2.86k stars 786 forks source link

ActivityUtils.getCurrentActivity() fails when dialog-styled activities change orientation #743

Closed renas closed 9 years ago

renas commented 9 years ago

From oaskaspo...@gmail.com on March 02, 2015 05:08:17

What steps will reproduce the problem? 1. Create two Activities, styling one of them as a dialog (see http://stackoverflow.com/questions/1979369/android-activity-as-a-dialog ).

  1. Make the first Activity launch the dialog-styled Activity.
  2. Rotate the screen.
  3. Call solo.assertCurrentActivity(TheDialogStyledActivity.class) or anything that ends up calling ActivityUtils.getCurrentActivity() What is the expected output? What do you see instead? ActivityUtils.getCurrentActivity() returns the parent Activity instead of the child, dialog-styled Activity. What version of the product are you using? On what operating system? Robotium 5.3.1 on Android 4.1.2 Please provide any additional information below. I have tracked down the Activity lifecycle callbacks and I've found out that when the device's orientation changes, the child Activity is reinstantiated first, followed by the parent Activity. It looks that Robotium listens on those callbacks, so that the most recently instantiated Activity is considered the one on the top of the Activity stack, causing ActivityUtils.getCurrentActivity() to return the wrong Activity.

Original issue: http://code.google.com/p/robotium/issues/detail?id=664

renas commented 9 years ago

From renasr...@gmail.com on March 03, 2015 09:27:20

Robotium uses an Activity Monitor to listen for new Activities. Unortunately the behaviour your experiencing comes from the ActivityMonotir.

You could try to use waitForActivity() instead or assertCurrentActivity().

Status: WontFix
Owner: renasr...@gmail.com