Hey, I have an application that logs on some sites using defaulthttpclient and I've found that I need it Use asyncTask as the request catches the UI threads. In my code, I make an example of a state class i.e. State State = New O2State (); With different states for different sites.
Then I call State .logon (string username, string password); Returns the string with the result's result:
string result = state.logon (username, password); I am trying to apply asynctasks to run this code in another thread and I am returning the string back to the UI thread. The idea is that I will display a progress dialog, run the thread, and when completed, will display a dialogue with the result.
I'm looking at this example:
Click on Public Zero (see V) {New Download Images (). Execute ("http://example.com/ image.png"); } Private class DownloadImageTask asyncTask protected {protected bitmap doInBackground (string ... url) {return loadImageFromNetwork (URL [0]); } PostExecute at safe zeros (bitmap result) {mImageView.setImageBitmap (results); }} Where I'm stuck: I do not think I need any argument, but to do this, a list of criteria is required. I am also unfamiliar with this time of law logic announcement.
Second: I'm not sure how to return the string as a result when the thread is finished executing. Should I just make a "DoThisWhenTheTreadIsFinished (string result)" and call it from PostExecute?
Anyway, I hope that it is not very misleading to read and I really appreciate any help you can offer. Thanks
Where you do not need parameters, just specify the type (such as string) and ignore it Or you can use zero range (note capital v).
Which suggestion is to return control to the UI thread to reflect updates, this is a good way. I.e., a method call on the activity to update the UI in POTEXAQ ()
As a general rule, if an operation takes more than a few hundred milliseconds, then use a different thread. You may also want to use the rotating progress indicator to show that the app is doing something.
(When people answer your questions, you always like them, and choose one as the "best" answer. By doing so, get points, and this later on to others Helps).
Comments
Post a Comment