Register to local broadcast inside a custom view
I suggest you to use a LocalBroadcastManager. It's like a BroadcastReceiver whose Intents can only be seen inside your application.
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// your code here
}
};
@Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
super.onPause();
}
@Override
protected void onResume() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter filter = new IntentFilter();
filter.addAction(MyClass.MY_ACTION);
lbm.registerReceiver(receiver, filter);
super.onResume();
}