1
廣播接收機廣播接收器的onReceive()不叫
mBroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.i(TAG,"contact list populate broadcast")
var action = intent.action
Log.v("Action is ",action)
when (action) {
GetContactListFromServer -> {
println("Get contact list")
}
}
}
}
val filter = IntentFilter(GetContactListFromServer)
this.registerReceiver(mBroadcastReceiver, filter)
這是我如何發送廣播
val i = Intent(ContactListActivity.Obz.GetContactListFromServer)
i.`package` = mApplicationContext?.getPackageName()
mApplicationContext?.sendBroadcast(i)
此代碼工作正常,直到昨晚。我無法調試出了什麼問題?
確定'mApplicationContext?.sendBroadcast(i)'被調用時'mApplicationContext'不等於'null'嗎? – miensol
是mApplicationContext不爲null @miensol –