Created
August 27, 2019 16:02
-
-
Save vlad-kasatkin/9ef5c81c037c44d4711b5dc3e39f6a6b to your computer and use it in GitHub Desktop.
Espresso Activity Actions (rewrite with new espresso APIs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object ActivityActions { | |
| fun backgroundActivity(activity: Activity) { | |
| val intent = Intent().apply { | |
| action = Intent.ACTION_MAIN | |
| addCategory(Intent.CATEGORY_HOME) | |
| } | |
| launchActivityWithIntent(activity, intent) | |
| } | |
| fun foregroundActivity(activity: Activity) { | |
| val intent = Intent(activity, EventListActivity::class.java).apply { | |
| flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | |
| } | |
| launchActivityWithIntent(activity, intent) | |
| } | |
| private fun launchActivityWithIntent(activityContext: Activity, intent: Intent) { | |
| InstrumentationRegistry.getInstrumentation().runOnMainSync { | |
| activityContext.startActivity(intent) | |
| } | |
| } | |
| fun foregroundActivityWhenIdle(activity: Activity) { | |
| onIdle() | |
| foregroundActivity(activity) | |
| } | |
| fun recreateActivity(activity: EventListActivity) { | |
| InstrumentationRegistry.getInstrumentation().runOnMainSync { | |
| activity.recreate() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment