Handler instance

The subclass needs to inherit the Hendler class and override the HandleMessage (Message Msg) method to accept thread data.

public class MainActivity extends Activity {

/** Called when the activity is first created. */ private WebView wv =null; private Handler h = new Handler(); public final String TAG = "UNISDP"; public final String MY_LOG = "my_log"; MyHandler myHandler; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); wv = (WebView) findViewById(R.id.web); WebSettings webSettings = wv.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setSaveFormData(false); webSettings.setSavePassword(false); webSettings.setSupportZoom(false); wv.addJavascriptInterface(new runJavaScript(), "myjs"); wv.loadUrl(sdFilePath); myHandler = new MyHandler(); MyThread m = new MyThread(); myThread m = new MyThread(); myThread m = new MyThread(); myThread m = new MyThread(); Thread getDataFromServer_thread = new Thread(m); getDataFromServer_thread.start(); }

The fetch thread fetches data from the page game server

class MyThread implements Runnable { public void run() { Message msg ; Bundle b ; while(true) { try { Thread.sleep(1000); msg = new Message(); b = new Bundle(); B. PutString ("value", "data sent to the UI thread..."); ); msg.setData(b); MainActivity.thiswww.sangpi.commyHandler.sendMessage(msg); } catch (interruptedException e) {e.printStackTrace();} interrupt (interrupt) {e.printStackTrace(); }}}} // This Handler runs class MyHandler extends Handler {public MyHandler() {} public with the main thread MyHandler(Looper L) { super(L); } public void handleMessage(Message MSG) {super.handleMessage(MSG);} public void handleMessage(Message MSG); // update the UI Bundle b = msg.getData(); String strValue = b.getString("value"); //MainActivity.this.button.append(color); Log.i(MY_LOG,strValue); }}