Skip to content

Instantly share code, notes, and snippets.

@GiuseppeGiacoppo
Last active February 19, 2022 14:03
Show Gist options
  • Save GiuseppeGiacoppo/dae731dd4dcfed925d2b5fddc8b45afe to your computer and use it in GitHub Desktop.
Save GiuseppeGiacoppo/dae731dd4dcfed925d2b5fddc8b45afe to your computer and use it in GitHub Desktop.
interface LogoutDelegate {
fun registerLogout(activity: AppCompatActivity)
}
class LogoutDelegateImpl: LogoutDelegate, DefaultLifecycleObserver {
private lateinit var activity: AppCompatActivity
override fun registerLogout(activity: AppCompatActivity) {
this.activity = activity
this.activity.lifecycle.addObserver(this)
}
private lateinit var logoutReceiver: BroadcastReceiver
override fun onCreate(owner: LifecycleOwner) {
logoutReceiver = LogoutReceiver()
activity.registerReceiver(logoutReceiver, IntentFilter("ACTION_LOGOUT"))
//unregister missing for keeping the sample code smaller!
}
inner class LogoutReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
activity.finish()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment