@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); } } }
}