本文共 708 字,大约阅读时间需要 2 分钟。
1.在Service中发送广播 Intent intent = new Int ent( BroadcastAction ); Bundle bundle = new Bundle(); bundle.putString("***", SUCCESS); bundle.putString("FullPathName", mFullPathName); intent.putExtras(bundle); sendBroadcast(intent); 2.在Activity中创建一个内部类MyBroadcastReceiver扩展Br oadcastReceiver,并在 其中 实现onRec eive方法。 3.在Activity中声明一个MyBroadcastReceiver类型 的成员 变量 ,并注册: private MyBroadcastReceiver myBroadcastRece iver; ... myBroadcastReceiver = new MyBroadcastReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction( BroadcastAction ); registerReceiver(receiver, filter ); 4.使用完后要记得释放 unregisterReceiver(receiver); 注:1和2中的 BroadcastAction 要是同一个Action 转载于:https://my.oschina.net/zhangjie830621/blog/100344