RobotiumTech / robotium

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

Solo.getCurrentActivity() can return wrong activity. #796

Open enikey87 opened 9 years ago

enikey87 commented 9 years ago

getCurrentActivity() can return wrong one when activity stack changes very fast.

For exampe:

In such cases solo.getCurrentActivity() will never return actual "current".

Reason is following execution chain:

renas commented 9 years ago

Thanks for reporting this.

On Mon, Nov 9, 2015 at 12:01 AM, enikey87 notifications@github.com wrote:

getCurrentActivity() can return wrong one when activity stack changes very fast.

For exampe:

  • Start ActivityB where onCreate() is { ... recreate() ... }
  • waitForActivity(ActivityB.class). // can return first instance of ActivityB cause of concurrency issues.
  • let wrongActivity = solo.getCurrentActivity().

In such cases solo.getCurrentActivity() will never return actual "current".

Reason is following execution chain: [UiThread]: new ActivityB.onCreate(). [Instrumentation]: Instrumentation.performOnCreate() { ... monitors.match(old Activity) } [UiThread]: old ActivityB.onDestroy(). [Instrumentation]: Instrumentation.performOnDestroy() { ... monitors.match(new Activity) } [ActivityMonitorThread]: waitForActivity() returns destroyed "old ActivityB" and "new ActivityB" is now lost forever.

— Reply to this email directly or view it on GitHub https://github.com/RobotiumTech/robotium/issues/796.

ArvindAbi commented 8 years ago

I am experiencing the same problem. But for me this is consistently reproducing when I enable "Don't Keep Activities" in Developer options iin the test device. If I disable the dev option. Its working fine for me..

francomucci commented 8 years ago

FYI ActivityLifecycleCallbacks can be used as workaround for this issue