the head is already ... the point is this.

There is a simple application consisting of one activite, one service and a broadcaster. Activiti starts the service, which in turn drives the notifications. Broadcast is used as an "alarm", that is, wakes up the device on a schedule. I need to make sure that the notification is updated on the next event in Broadcast (to put it simply, there’s not enough mind how to get to the functions in the service) ...
I even tried to bind, but I quickly realized that this was a bad idea .. I even had an idea to do it through global variables ... how can I do this?

  • Data in the service can be sent via IBinder which will return after OnServiceConnected. What kind of information do you want to transmit? The logic of creating notifications in the service is? Then you can create a PendingIntent / Intent service from your service and show it through the NotificationManager, it will open when the user clicks on the notification. - Serge Markov
  • Yes, for now, I just need to send to the service that the receiver has worked on a timer. - baralgin1003

2 answers 2

Transfer the intent (into which the necessary data was onStartCommand() ) from the BroadcastReceiver into the service and parse / process in onStartCommand() . Show / update notifications.

  • in the receiver I registered intentToSevr = new Intent (context, NotificationService.class); Bundle bundle = new Bundle (); bundle.putString ("EXTRA", "1"); intentToSevr.putExtras (bundle); in the service public int onStartCommand (Intent intent, int flags, int startId) {String message = intent.getStringExtra ("EXTRA"); Toast.makeText (this, message, Toast.LENGTH_SHORT) .show (); return super.onStartCommand (intent, flags, startId); } but it only works when the service is first launched - baralgin1003
  • Register return START_STICKY in onStartCommand() - VAndrJ

Get out of the situation like this

 public void onReceive(Context context, Intent intent) { Intent in = new Intent("AppService"); in.putExtra("Data","ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° связи."); context.sendBroadcast(in); } 

and reception in the service:

  public int onStartCommand(Intent intent, int flags, int startId) { //РСгистрация ΠΏΡ€ΠΈΠ΅ΠΌΠ½ΠΈΠΊΠ° IntentFilter filter = new IntentFilter(); filter.addAction("AppService"); BroadcastReceiver service = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("AppService")) { String message = intent.getStringExtra("Data"); Toast.makeText(context,message,Toast.LENGTH_LONG).show(); } } }; registerReceiver(service, filter); return super.onStartCommand(intent, flags, startId); } 

it seems to work. I don't know how competent it is