java - Passing value from helper thread to main thread -
I have a thread with an attempt-blocking block inside the try block I have HTML stored in the variable I have to load in the webview. Now Android / Java does not allow web thru to go anywhere as the main thread.
How can I pass this string variable value outside of the thread? . Announcing that the string variable does not help finalizing and threading out
public class MyCustomView LinearLayout {// UI element extends Private WebView mWebView; Last activity activity = (activity) this.getContext (); New thread (New Runnable) {@Override Public Zero Run (try using {// thread} because network URL obj = new URL (adrequesturl); HttpURLConnection thief = (HttpURLConnection) obj.openConnection (); con SetRequestMethod ("GET"); if (con.getResponseCode () == 200) {// ***** Main thread string dataToLoad = "some_custom_html" requires the value of this variable; // mWebView is the web view that I have created and can not implement the supporting thread below: //mWebView.loadData(dataToLoad, "text / html" inside, "utf-8"); -} else {// some code}} (exception e ) {// some code } } }).Start(); // ** Solution which activity for me ** Ronnu UIthread (new runleball) (public zero run) {mWebView.loadData (DataToLoad, "text / html", "utf-8");}}); // Now we're back to the main thread // ******** main problem *************************************************************** DataToLoad value can not be found here //mWebView.loadData (DataToLoad, "text / html", "utf-8"); } "itemprop =" text "> You can play a part of the code in the UI thread like this:
< / P>
this.getContext (). RunOnUiThread (new runnab) {public void run (mWebView.loadData (dataToLoad, "text / html", "utf-8"}}}});
Comments
Post a Comment