码迷,mamicode.com
首页 > 其他好文 > 详细

Service 广播 到Fragment

时间:2016-05-02 16:58:07      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

    //Fragment

     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      
              System.out.println("oncreate");
          
         //代码 注册 广播接收器
          Receiver=new myReceiver();
          IntentFilter filter=new IntentFilter();
          filter.addAction("zcd.voicerobot");
          getActivity().registerReceiver(Receiver,filter); 
            
    }  //http://www.cnblogs.com/xiaobo-Linux/  赵存档 QQ463431476

    //内部类  广播接收

 public class myReceiver extends BroadcastReceiver {
   
    public void onReceive(Context context, Intent intent) {
        
        String msg = intent.getStringExtra("message");
         Toast.makeText(context, "广播已经接收", Toast.LENGTH_SHORT).show();
        text.setText("我说:"+msg);
      
    }
}


//service


    public  void UpdateGUI()
     {
         
         //broadcast 
          // service 通过广播来更新GUI
            Intent intent=new Intent();
            intent.putExtra("message",text);
            intent.setAction("zcd.voicerobot");
            sendBroadcast(intent);
     }
         

 

Service 广播 到Fragment

标签:

原文地址:http://www.cnblogs.com/xiaobo-Linux/p/5452445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!