android中broadcastReceiver用法
BroadcastReceiver是消息广播,
BroadcastReceiver的生命周期很短,在收到消息广播后,就结束了。
即onReceive()后,生命周期只有10秒左右。
注册方式有两种,一种在androidManifest.xml中注册,
<receiver android:name = ".MyBroadcastReceiver" > <intent-filter android:priority = "1000" > <action android:name = "android.provider.Telephony.SMS_RECEIVED" /> </intent-filter > </receiver >
还有一种是在activity中注册
/** * 恢复播放 */ @Override protected void onResume() { super.onResume(); // 注册LRC广播接收器和进度条广播接收器 lrcReceiver = new LrcMessageBroadcastReceiver(); registerReceiver(lrcReceiver, getLrcIntentFilter()); } /** * Description 生成IntentFilter的途径有两种,一个是在androidManifest.xml中定义,一个是在程序中定义 * @return */ private IntentFilter getLrcIntentFilter(){ if(lrcFilter == null){ lrcFilter = new IntentFilter(); lrcFilter.addAction(Constant.LRC_MESSAGE_ACTION); lrcFilter.addAction(Constant.PROGRESS_MESSAGE_ACTION); } return lrcFilter; }
相关推荐
xilove0 2020-01-14
fuzhangandroid 2011-04-07
老菜鸟自习室 2011-08-05
mingming 2015-01-13
taiyuanwuyin 2015-03-31
xzw 2016-06-06
故作坚强 2015-03-31
chenjinlong 2020-04-06
magic00 2020-01-10
xilove0 2019-12-09
ThedakeLaugh 2010-08-23
StarkHuang 2014-09-04
易辰Android 2012-05-08