Start Broadcast Receiver from an activity in android

后端 未结 4 694
我在风中等你
我在风中等你 2020-12-09 04:04

I would like to start a broadcast receiver from an activity. I have a Second.java file which extends a broadcast receiver and a Main.java file from which I have to initiate

4条回答
  •  鱼传尺愫
    2020-12-09 04:26

    For that you have to broadcast a intent for the receiver, see the code below :-

    Intent intent=new Intent();
    getApplicationContext().sendBroadcast(intent);
    

    You can set the action and other properties of Intent and can broadcast using the Application context, Whatever action of Intent you set here that you have to define in the AndroidManifest.xml with the receiver tag.

提交回复
热议问题