Skip to content

Commit 4b9c19f

Browse files
Paige McAuliffecopybara-androidxtest
authored andcommitted
Get first activity when there are multiple resumed activities in getResumedActivityOrNull()
PiperOrigin-RevId: 636554108
1 parent 404ac0d commit 4b9c19f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

espresso/device/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
**Bug Fixes**
88

9+
* Add support for setting screen orientation with multiple resumed activities
10+
911
**New Features**
1012

1113
**Breaking Changes**

espresso/device/java/androidx/test/espresso/device/common/ActivityUtil.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import java.util.concurrent.CountDownLatch
3030
import java.util.concurrent.TimeUnit
3131

3232
/** Collection of utility methods for interacting with activities. */
33-
private val TAG = "ActivityUtil"
33+
private const val TAG = "ActivityUtil"
3434

3535
/**
3636
* Detects if configuration changes are handled by the activity.
@@ -42,7 +42,7 @@ private val TAG = "ActivityUtil"
4242
*/
4343
@RestrictTo(Scope.LIBRARY)
4444
fun Activity.isConfigurationChangeHandled(configBit: Int): Boolean {
45-
val activityInfo = this.getPackageManager().getActivityInfo(this.getComponentName(), 0)
45+
val activityInfo = this.packageManager.getActivityInfo(this.componentName, 0)
4646
return (activityInfo.configChanges and configBit) != 0
4747
}
4848

@@ -60,11 +60,12 @@ fun getResumedActivityOrNull(): Activity? {
6060
val activities: Collection<Activity> =
6161
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED)
6262
if (activities.size > 1) {
63-
val activityNames = activities.map { it.getLocalClassName() }
63+
val activityNames = activities.map { it.localClassName }
6464
Log.d(
6565
TAG,
66-
"More than one activity was found in the RESUMED stage. Activities found: $activityNames"
66+
"More than one activity was found in the RESUMED stage. Activities found: $activityNames",
6767
)
68+
activity = activities.first()
6869
} else if (activities.isEmpty()) {
6970
Log.d(TAG, "No activity found in the RESUMED stage. Waiting up to 2 seconds for one.")
7071
val latch = CountDownLatch(1)

0 commit comments

Comments
 (0)