Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a broadcast only to specific Activity

I have one Activity which creates a BroadcastReceiver with an IntentFilter in the method onCreate(...):

IntentFilter iFilter = new IntentFilter("action");

receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
};

registerReceiver(receiver, iFilter);

On the other side is an IntentService, which shall send some data:

Intent intent = new Intent(getApplicationContext(), receiver.class);
intent.setAction("action");

[...]

sendBroadcast(intent);

But it seems not to work. No Broadcast ist received.
My service class is in an android lib, perhaps this makes trouble.

Thanks for any advices.

like image 250
CSchulz Avatar asked Jul 14 '11 17:07

CSchulz


1 Answers

if the intent is inside your app only, consider using LocalBroadcastManager

like image 116
android developer Avatar answered Nov 15 '22 18:11

android developer