zoukankan      html  css  js  c++  java
  • activity 与service 的广播

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.common_down_layout);
            AppManager.appManager.getActivities().add(this);
            backBtn = (Button) this.findViewById(R.id.back_btn);
            backBtn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            receiver = new UpdateReceiver();
            receiver.registerAction(AppConstant.LocalActivityConstant.update_action);
    class UpdateReceiver extends BroadcastReceiver
        {
            
            public void registerAction(String action)
            {
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction(action);
    public class LocalActivityConstant
    	{
    		public static final String update_action="updateUI";
    		public static final String update_down_done_action = "done_updateui";
    	}
    service类发送广播    
    Intent intent = new Intent();
                    intent.setAction(AppConstant.LocalActivityConstant.update_action);
                    intent.putExtra("completeSize", size);
                    intent.putExtra("url", url);
                    mContext.sendBroadcast(intent);
    
    

      

    registerReceiver(this, intentFilter); } @Override public void onReceive(Context context, Intent intent) { //接收来自DownloadService传送过来的数据,并且更新进度条 if(intent.getAction().equals(AppConstant.LocalActivityConstant.update_action)) { String url=intent.getStringExtra("url"); int completeSize = intent.getIntExtra("completeSize", 0); adapter.setPercents(url, completeSize); } } }
    
    
    
    
        }
  • 相关阅读:
    最近迷上用dvd字幕学习英语
    原始套接字
    c语言socket编程
    inet_aton和inet_network和inet_addr三者比较
    用man来查找c函数库
    ubuntu的系统日志配置文件的位置
    复制文件
    vim复制粘贴解密(转)
    vim的自动补齐功能
    两个数据结构ip和tcphdr
  • 原文地址:https://www.cnblogs.com/gfqFighting/p/2975464.html
Copyright © 2011-2022 走看看