java正則表達式解析html示例分享。本站提示廣大學習愛好者:(java正則表達式解析html示例分享)文章只能為提供參考,不一定能成為您想要的結果。以下是java正則表達式解析html示例分享正文
本文實例講述了Android准時器和Handler用法。分享給年夜家供年夜家參考。詳細剖析以下:
1、情況:
主機:WIN8
開辟情況:Android Studio
2、准時器應用示例:
初始化:
//准時器 private Timer Timer_Work = new Timer(); //任務距離,單元:ms private final int INTERVAL_WORK = 5000;
創立准時器線程:
/** * 結構函數 */ public Config() { //生成設置裝備擺設信息 generate_config_info(); //創立准時線程 Timer_Work.schedule(new Task(), INTERVAL_WORK, INTERVAL_WORK); // 准時義務 }
新建義務:
/** * 准時器線程准時任務 */ private class Task extends TimerTask { @Override public void run() { generate_config_info(); } }
3、准時器和Handler組合任務,更新UI示例(准時器線程不克不及直接更新UI):
准時器義務:
/** * 准時器線程准時任務 */ private class Task extends TimerTask { @Override public void run() { if (get_state() == ENUM_State.FREE) { connect("10.58.1.59",8906); } if (get_state() == ENUM_State.CONNECT_SUCCESS) { login("TianTian",""); } if (get_state() == ENUM_State.LOGIN_SUCCESS) { enter_room(1,""); } if (get_state() == ENUM_State.ENTER_ROOM_SUCCESS) { Message message = new Message(); message.what = 1; handler.sendMessage(message); } } }
Handler處置信息:
private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: { System.out.println("sdk翻開視頻預備"); video(-224); break; } } super.handleMessage(msg); } };
4、Handler和Runnable組合發生線程示例:
延時200ms挪用runnable
handler.postDelayed(runnable, 200);
發生線程:
Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { try { int videoBitrate = anychatSDK.QueryUserStateInt(userID, AnyChatDefine.BRAC_USERSTATE_VIDEOBITRATE); if (videoBitrate > 0) { handler.removeCallbacks(runnable); mOtherView.setBackgroundColor(Color.TRANSPARENT); } handler.postDelayed(runnable, 200); } catch (Exception e) { e.printStackTrace(); } } };
願望本文所述對年夜家的Android法式設計有所贊助。