Kotlin 本地广播

1、发送广播

   var intent = Intent("actionName")

   LocalBroadcastManager.getInstance(Context).sendBroadcast(intent)

2、注册广播

    LocalBroadcastManager.getInstance(sContext).registerReceiver(receiver, IntentFilter("actionName"))

    val receiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
             //TODO
        }
    }

3、销毁广播

LocalBroadcastManager.getInstance(Context).unregisterReceiver(receiver)

 

 

-- NORMAL --

你可能感兴趣的:(Kotlin 本地广播)