0

I have a service that is defined to run on it's own process:

<service
            android:name="com.package.MyService"
            android:enabled="true"
            android:process=":remote">

and I have a class that runs that service:

Intent intent = new Intent(context, MyService.class);
        intent.setAction(Constants.ACTION);
        context.startService(intent);

I am trying to broadcast an Intentas following:

Intent broadcastIntent = new Intent(RECEIVER);
        broadcastIntent.setAction(action);
        broadcastIntent.putExtra(DATA, msg);
        sendBroadcast(broadcastIntent);

here I declare my receiver:

private final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //doSomething
    };

but it seems like the onReceive is never called

gilgil28
  • 540
  • 5
  • 12
  • Where are you registering this receiver? – CommonsWare Sep 12 '16 at 18:57
  • when I instantiate the class. It gets in the constructor a Context (this is a Unity3D project) – gilgil28 Sep 12 '16 at 19:01
  • How exactly are you registering the Receiver? It looks like you're instantiating your broadcast `Intent` with one action, then setting another. You sure you've got the correct `IntentFilter` for your Receiver? – Mike M. Sep 12 '16 at 19:23
  • `context.registerReceiver(receiver, new IntentFilter( Constants.RECEIVER));` and `Intent broadcastIntent = new Intent(RECEIVER); broadcastIntent.setAction(action); broadcastIntent.putExtra(DATA, msg); sendBroadcast(broadcastIntent);` – gilgil28 Sep 13 '16 at 08:43
  • That would probably be the problem, then, or, at least one of them. An `Intent` can only have one action. You instantiate the broadcast `Intent` with `RECEIVER`, but then you change it to `action`. You're filtering for `RECEIVER`, which presumably is not the same as `action`. – Mike M. Sep 13 '16 at 10:36

0 Answers0