Android 輪循的處理 Handler:
- private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- Log.d(TAG,"BroadcastReceiver: intent action :" + action);
- resultHandle();
- }
- };
- private void resultHandle(){
-
- Message msgget = Message.obtain();
- msgget.what = MSG_TIMER;
- handler.sendMessageDelayed(msgget, 6L);
- }
-
- private final Handler handler = new Handler() {
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- switch (msg.what) {
- case MSG_TIMER:
- mWorker = new HandlerThread("MyWorker");
- mWorker.start();
- mWorkerHandler = new Handler(mWorker.getLooper());
- mWorkerHandler.postDelayed(new MessageReceiveTask(),
- SECONDRESOLVERMESSAGE);
- break;
- }
- }
- };
- class MessageReceiveTask implements Runnable {
- public void run() {
- if(isState){
-
- }else {
- mWorkerHandler.postDelayed(this, SECONDRESOLVERMESSAGE);
- }
- }
- }
- private final long SECONDRESOLVERMESSAGE = 6L;
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11