Android开发中怎么把广播中处理后的信息传递给Activity?
在一个Activity中注册了一个动态广播,这个广播是监听特定的短信,当收到我需要的短信时,需要给Activity中传递一个信息,我改怎么传递这个信息?...
在一个Activity中注册了一个动态广播,这个广播是监听特定的短信,当收到我需要的短信时,需要给Activity中传递一个信息,我改怎么传递这个信息?
展开
2个回答
展开全部
1.发送广播
Intent intent = new Intent(BroadcastAction);
Bundle bundle = new Bundle();
bundle.putString("***", SUCCESS);
bundle.putString("FullPathName", mFullPathName);
intent.putExtras(bundle);
sendBroadcast(intent);
2.在Activity中创建一个内部类MyBroadcastReceiver扩展BroadcastReceiver,并在其中实现onReceive方法。
3.在Activity中声明一个MyBroadcastReceiver类型的成员变量,并注册:
private MyBroadcastReceiver myBroadcastReceiver;
...
myBroadcastReceiver = new MyBroadcastReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(BroadcastAction);
registerReceiver(receiver, filter);
4.使用完后要记得释放
unregisterReceiver(receiver);
注:1和2中的 BroadcastAction要是同一个Action
Intent intent = new Intent(BroadcastAction);
Bundle bundle = new Bundle();
bundle.putString("***", SUCCESS);
bundle.putString("FullPathName", mFullPathName);
intent.putExtras(bundle);
sendBroadcast(intent);
2.在Activity中创建一个内部类MyBroadcastReceiver扩展BroadcastReceiver,并在其中实现onReceive方法。
3.在Activity中声明一个MyBroadcastReceiver类型的成员变量,并注册:
private MyBroadcastReceiver myBroadcastReceiver;
...
myBroadcastReceiver = new MyBroadcastReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(BroadcastAction);
registerReceiver(receiver, filter);
4.使用完后要记得释放
unregisterReceiver(receiver);
注:1和2中的 BroadcastAction要是同一个Action
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询