Service:
//在你需要传值的地方发送一个
/intent.putExtra("mesSum", data):这是需要传的参数
//intent.action = "com.wimi.wsapp.framework.MessageService":这是Service所在位置
val intent = Intent() intent.putExtra( "mesSum" , data) intent. action = "com.wimi.wsapp.framework.MessageService" sendBroadcast(intent)Activity:
//注册广播接收器 var receiver = MyReceiver() val filter = IntentFilter() filter.addAction("com.wimi.wsapp.framework.MessageService") activity.registerReceiver(receiver,filter)
inner class MyReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val bundle = intent.extras val count = bundle!!.getInt("mesSum") if(count>0){ isViewActiveRunNow{ pointRed.visibility=View.VISIBLE } }else{ isViewActiveRunNow { pointRed.visibility = View.GONE } } }}