Skip to content

Instantly share code, notes, and snippets.

@Sethathi
Created March 24, 2022 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sethathi/3b0fc0d869e16e583867ca42fffb814d to your computer and use it in GitHub Desktop.
Save Sethathi/3b0fc0d869e16e583867ca42fffb814d to your computer and use it in GitHub Desktop.
// Can you spot any issues with code?
class MyBroadcastReceiverActivity : AppCompatActivity() {
private var broadcastReceiver: BroadcastReceiver? = null
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_one)
}
private fun registerBroadCastReceiver() {
broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
// Do some UI work
}
}
registerReceiver(broadcastReceiver, IntentFilter("currency-changed-event"))
}
override fun onStart() {
super.onStart()
registerBroadCastReceiver()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment