Reputation: 1073
I want to know whether an app can be a BroadcastReceiver and sender? Please expain with an example.
Upvotes: 0
Views: 1447
Reputation: 49410
If by app you mean activity, so yes you can but you will have to embed your BroadcastReceiver
in your activity and register/unregister it yourself. That way, you just need to add your activity as Activity
in the Manifest and you activity will be able to receive a broadcast and send broadcast as well.
I m not too sure how it behaves in term of life cycle though. You will need to look it up if it s what you want.
Upvotes: 1
Reputation: 43088
Application can't be a BroadcastReceiver. BroadcastReceiver is an application component. But answer to your question is yes: you can send broadcasts from one component and receive it in another.
For ex. in activity:
Intent intent = new Intent(...);
sendBroadcast(intent);
In receiver:
@Override
public void onReceive(Context context, Intent intent) {
// here is your intent
}
Upvotes: 2