关闭

android 自定义广播

标签: android 自定义广播
47人阅读 评论(0) 收藏 举报
分类:

首先先定义一个广播action

广播actiong String flag = “android.intent.action.MyBorad”

1,接收广播

private void startReceiver() {
    broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    intentFilter = new IntentFilter();
    intentFilter.addAction(flag);
    bordcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (TaskServer.newCauseDataList != null) {
                badgecause.showNum(badgecause, imgBtn_cause, TaskServer.newCauseDataList.size());
            }
            if (TaskServer.newTaskDataList != null) {
                badgetask.showNum(badgetask, imgBtn_task, TaskServer.newTaskDataList.size());
            }
        }
    };
    broadcastManager.registerReceiver(bordcastReceiver, intentFilter);
}

2,发送广播
private void sendBoard() {
    Intent broadcast = new Intent(flag);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1404次
    • 积分:125
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:4篇
    • 译文:0篇
    • 评论:0条