http://pan.baidu.com/s/1qWPmGuo 下载后将.bmp改名为.zip解压
实现
基于BroadcastReceiver和Service改造TimerTracker
参考资料:
http://blog.csdn.net/teddy99999/article/details/28131547
http://www.cnblogs.com/zhangdongzi/archive/2012/01/08/2316217.html
Service使用
Service相关成员变量
TimerService mLocalService;
ServiceConnection mSc = new ServiceConnection(){
@Override
public void onServiceConnected(ComponentName name,IBinder binder){
mLocalService = ((TimerService.LocalBinder)binder).getService();
}
@Override
public void onServiceDisconnected(ComponentName name){
mLocalService = null;
}
};
绑定Service
Intent service = new Intent(this.getApplicationContext(),TimerService.class);
this.bindService(service, mSc, Context.BIND_AUTO_CREATE);
BroadcastReceiver使用
BroadcastReceiver相关成员变量
public final static String ACTION_TIME_UPDATE = "update";
public final static String ACTION_TIMER_FINISHED = "finished";
private BroadcastReceiver mTimerReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context,Intent intent){
if( intent.getAction().equals(ACTION_TIME_UPDATE) ){
Long time = intent.getLongExtra("time", 0) / 1000;
TextView counter = (TextView) findViewById(R.id.counter);
counter.setText(DateUtils.formatElapsedTime(time));
}
else if( intent.getAction().equals(ACTION_TIMER_FINISHED) ){
Long time = intent.getLongExtra("time", 0);
CounterUpdate(0);
Log.i("TEST","get finished");
mTimeListAdapter.add(time/1000);
}
}
};
BroadcastReceiver注册
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_TIME_UPDATE);
filter.addAction(ACTION_TIMER_FINISHED);
registerReceiver(mTimerReceiver,filter);