zzwendy / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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).

2. Make the first Activity launch the dialog-styled Activity.

3. Rotate the screen.

4. 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 reported on code.google.com by oaskaspo...@gmail.com on 2 Mar 2015 at 1:08

GoogleCodeExporter commented 9 years ago
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(). 

Original comment by renasr...@gmail.com on 3 Mar 2015 at 5:27