尝试广播标志,但在接收时我得到" null"。有人可以指导我。以下是我的发件人和收件人代码。
发送:
Intent sendableIntent = new Intent("abc");
sendableIntent.putExtra("kicked", prefs.getSurveySubmittedStatus(context));
LocalBroadcastManager.getInstance(AcrService.this).sendBroadcast(sendableIntent;
Log.d("TAG", "SDK : Broadcast Send is : " + prefs.getSurveySubmittedStatus(context));
接收:
protected void onResume(){
super.onResume();
Log.d("TAG", "Inside onResume");
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("abc"));
}
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
String message = intent.getStringExtra("kicked");
Log.d("TAG", "Received Broadcast : " + message);
//Getting null here, whereas I should receive "true or false"
}
};
@Override
protected void onDestroy() {
super.onDestroy();
// Unregister since the activity is about to be closed.
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}