I was facing the same issue with my app, what I do is use LocalBroadcastManager instead of context. Android documents also suggest using LocalBroadcastManager for sending in-app broadcast receivers.
//register your receiver like this
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("custom-event-name"));
// unregister like this
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
// broadcastlike this
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
Hope this will help. Thanks! :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…