android - Using a broadcast intent/broadcast receiver to send messages from a service to an activity -


So I understand (I think) about broadcasting purposes and to get them the message.

So now, my problem / which I can not work for is to send a message to the effect of a receiver for onReiveive , say that I have a receiver :

  Public Class Receive Message Broadcast Extends Expand Receiver {@ Override Public Records on Receive (context reference, intent intent) {string action = intent.action}; If (action.equalsIgnoreCase (TheService.DOWNLOADED)) Send a message to {// activity}}}   

How do I send a message to an activity?

I have to instantinate the receiver in the activity that I want to send messages and monitor it in some way? what else? I understand this concept, but in reality there is no application.

Any help will be absolutely amazing, thanks.

edit Broadcast receiver Corrected examples and manual declarations for registration / unregistered were also deleted. Define

get message as an internal class within activity for which to hear messages from service Is required.

Then, declare square variables like ...

  get message myReceiver = null; Boolean my receiver ISR registered = false; Use  onCreate ()  in   

myReceiver = new ReceiveMessages ();

Then onResume () ...

  (MyReceiverIsRegistered) {Register Receiver (myReceiver, New IntentFilter (" Com.mycompany.myapp.SOME_MESSAGE ")); MyReceiverIsRegistered = True; }   

... and in onPause () ...

  if (myReceiverIsRegistered) {unregistered receiver (myReceiver) ; MyReceiverIsRegistered = false; } Create and broadcast  intent  in   

service ...

  Intent I = new intention ("Com.mycompany.myapp.SOME_MESSAGE"); SendBroadcast (i);   

And that's about it, make 'action' unique for your package / app, i.e., com.mycompany ... as my example. This helps avoid situations where other apps or system components may try to process it.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -