How do I contact the broadcast service using the broadcast receiver?

Hope someone can help me here. I will try to be brief!

I have a widget that launches a service. The service registers two broadcast receivers. I would like to send back intentions from receivers to the service so that the service can respond.

I believe that I read somewhere that the “start” of a service works several times, for example. follow these steps in receivers:

serviceIntent.setAction("me.SERVICE");
intent.putExtra("me.SERVICE", somedata);
context.startService(serviceIntent);

I remember reading (on some blog) that this will not launch a new service, but simply convey the intention to the already running service. It's right? Is this a bad way to do this? Is there a better way?

Many thanks!

Jack

+3
source share
2 answers

, 2.0.

+1

, . ( 'this') onCreate, , getInstance(), . MyService.getInstance(), .

0

Source: https://habr.com/ru/post/1760173/


All Articles