Skip to content

Instantly share code, notes, and snippets.

@vlad-kasatkin
Created August 27, 2019 16:02
Show Gist options
  • Select an option

  • Save vlad-kasatkin/4da0aebafac4448f2e5839bbeb40635d to your computer and use it in GitHub Desktop.

Select an option

Save vlad-kasatkin/4da0aebafac4448f2e5839bbeb40635d to your computer and use it in GitHub Desktop.
Espresso Activity Actions (rewrite with new espresso APIs)
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