一.发送系统广播 |
1 .发送标准广播 |
在一个Activity中,点击按钮,然后执行相应的代码: |
public void click(View view) { |
Intent intent = new Intent( "com.example.my" ); |
sendBroadcast(intent); |
} |
2 .发送有序广播 |
public void click(View view) { |
Intent intent = new Intent( "com.example.my" ); |
sendOrderedBroadcast(intent, null ); |
} |
区别: 就是调用的函数不一样,参数不一样 |
sendOrderedBroadcast第二个参数是与权限有关 |
二.发送标准广播 |
//其实跟系统广播差不多,多了个LocalBroadcastManager 对象 |
public void click(View view) { |
LocalBroadcastManager localBroadcastManager=LocalBroadcastManager.getInstance( this ); |
Intent intent= new Intent( "com.my.localBroadCast" ); |
localBroadcastManager.sendBroadcast(intent); |
} |
by: 发表于:2017-09-26 11:44:24 顶(0) | 踩(0) 回复
??
回复评论