Reputation: 169
Im quite new on Android programming, so I have some basic doubts.
There is an App here that do not have the BroadcastReceiver, but I used other class instead, and I am sure that it works properly.
I read in some topics, that i need to register It in manifest, but I have no clue how to do It; and I got confused about com.google.android.c2dm.permission.SEND
and etc, I do not know how to set it.
Question: Can I ask for someone explain to me, in simple way, what I need to do to my method be executed while the app is closed, AND, how i register it on manifest?
Thanks!
Upvotes: 0
Views: 36
Reputation: 5096
BroadcastTeceiver as the name imply is component that could receive data that someone send via Intents. The sender could be the system, other App or your App itself.
There are to ways to regiester BroadcastReceiver:
In the manifest by exlixit the Intent you want to listen.
In code by give it Intent_filter programmatically.
Upvotes: 0
Reputation: 1904
Send an Intent
is the way of Android of telling to everyone that some event occured.
For instance where your device receive a call an Intent
is broadcast. But to be specific to some event every Intent
has an action. For instance the Intent
broascast when you receive a SMS has the "android.provider.Telephony.SMS_RECEIVED"
action.
In your AndroidManifest.xml
you can register objects for specific intents. You can register Activity
, Service
and BroadcastReceiver
.
To register a BroadcastReceiver
to "receive sms action" you do the following in your manifest :
<receiver android:name="your.receiver.class">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
This means that every time an Intent
with the specified action is fired, it will be pass to your receiver. This means that his onReceive
method will be called with the intent as param.
So to create some code that will be executed will your app is closed, follow this steps :
Create a class that extends BroadcastReceiver
.
Put your code in the onReceive
method. This method will be call every time your receiver receive an intent.
Register your receiver for the desired action in your AndroidManifest.xml
file.
Upvotes: 1