Last active
February 19, 2022 14:03
-
-
Save GiuseppeGiacoppo/dae731dd4dcfed925d2b5fddc8b45afe to your computer and use it in GitHub Desktop.
This file contains 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
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