Skip to content

Instantly share code, notes, and snippets.

@jraska
Created February 16, 2020 16:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jraska/39997a1ce0bab07b9e89499a390b8baa to your computer and use it in GitHub Desktop.
Save jraska/39997a1ce0bab07b9e89499a390b8baa to your computer and use it in GitHub Desktop.
class PushCallbacks(
val pushStream: PushStream
) : Application.ActivityLifecycleCallbacks, PushStream.OnPush {
private var foregroundActivity: Activity? = null
override fun onActivityResumed(activity: Activity) {
foregroundActivity = activity
pushStream.register(this)
}
override fun onActivityPaused(activity: Activity) {
pushStream.unregister(this)
foregroundActivity = null
}
override fun onPush(push: PushMessage) {
foregroundActivity?.let { showMessage(it, push) }
}
private fun showMessage(activity: Activity, pushMessage: PushMessage) { ... }
// Other methods are empty
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment