How should I implement a broadcast receiver & filter so that it can response to multiple intents.  
private BroadcastReceiver myReceiver;
IntentFilter myFilter = new IntentFilter();
onCreate():
    myFilter.addAction("first");
    myFilter.addAction("second");
    myReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // do different actions according to the intent
            }
        };
    registerReceiver(myReceiver, myFilter);
from my fragment:
Intent i = new Intent("first"); sendBroadcast(i);
Intent i = new Intent("second"); sendBroadcast(i);
Thanks
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if(action != null) {
        if(action.equals("action1") {
            // CODE
        } else if (action.equals("action2") {
            // CODE
        }
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With