yep,I quite agree with Mark Murphy,this phenomenon sounds a little bit tricky, the underlying principle involves the mechanism of threads and loops of android. In android, each threads correspond to only one loop which handles events come from UI ,or app, or other whatsoever.You may create an sub threads,but if you want to utilize the parent UI,or change the parent UI, error occurs. The solution, I guess, may create another loop corresponds to sub threads. Or, just try what Mark Murphy suggested.Good luck, here I give you an link, there is a part of it talking about the basic mechanism of loop of android. http://sites.google.com/site/io/inside-the-android-application-framework
在2009-02-18,"Mark Murphy" <[email protected]> 写道: > >Mak wrote: >> Hi. >> I'd like to build an application that loads different urls in a >> webview. >> I prefered the webview cause that gives the chance of deleting cache >> and >> things like that. >> But loading an URL in a loop has the effect that everything but the >> webView >> is executed, till the end of the loop. >> >> for(int i = 0; i < 10; i++) { >> WebView ansicht = new WebView(getBaseContext()); >> ansicht.loadUrl(adress.toString()); >> setContentView(ansicht); >> ansicht.clearCache(true); >> sleep(15000); >> System.out.println("instead something else"); >> } >> >> i get the print "instead something else" every 15 seconds and after 10 >> times >> the url will be loaded. >> >> Why can't the webView be called in a loop? >> What's my fault? > >You're not letting Android do anything. > >This is not a WebView thing -- if your code was updating a TextView with >some new text, you would see the same thing. > >Android, like many GUI frameworks, works off of a message loop. Method >invocations, such as setting text in a TextView or loading a URL in a >WebView, will only post messages to a queue the loop works off of. Those >messages will not be processed *until you return control to Android* by >exiting onCreate() or whatever other callback you are in. > >Generally speaking, don't use sleep() in Android, particularly in UI logic. > >Instead, use postDelayed() on the WebView to cause the next URL to be >loaded in sequence after a delay, and get out of onCreate() or wherever >this code is. > >-- >Mark Murphy (a Commons Guy) >http://commonsware.com >_The Busy Coder's Guide to Android Development_ Version 2.0 Available! > >> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

