post your error messages

On Nov 7, 11:16 am, Bobbie <[EMAIL PROTECTED]> wrote:
> @ zl25drexel
>
> Here is my code, I tried your tutorial, it doesn't work...?  I'm
> guessing I have something wrong.  Where should I call this?  Which
> function do I call?  Sorry, I'm a beginner at this.
>
>         // Need handler for callbacks to the UI thread
>     final Handler mHandler = new Handler();
>
>     // Create runnable for posting
>     final Runnable mUpdateResults = new Runnable() {
>         public void run() {
>                 chatscreen.append((CharSequence) mHandler);
>         }
>     };
>
>     protected void chatUpdater() {
>
>         // Fire off a thread to do some work that we shouldn't do
> directly in the UI thread
>         Thread t = new Thread() {
>             public void run() {
>                 // get chat updates
>                                 HttpClient updateclient = new 
> DefaultHttpClient();
>                                 HttpPost updatepost = new 
> HttpPost("https://www.net/chatpost.php?
> action=updatechat");
>                             ResponseHandler<String> responseHandler = new
> BasicResponseHandler();
>                             String responseBody;
>                                 try {
>                                         // send message
>                                         responseBody = 
> updateclient.execute(updatepost,
> responseHandler);
>                                         mHandler.post(mUpdateResults);
>                                 } catch (ClientProtocolException e) {
>                                         // error sending message
>                                         mHandler.post(mUpdateResults);
>                                 } catch (IOException e) {
>                                         // error sending message
>                                         mHandler.post(mUpdateResults);
>                                 }
>             }
>         };
>         t.start();
>     }
>
> On Nov 7, 9:38 am, zl25drexel <[EMAIL PROTECTED]> wrote:
>
> > see my post 
> > athttp://bend-ing.blogspot.com/2008/11/properly-handle-progress-dialog-...
>
> > On Nov 7, 9:30 am, David Given <[EMAIL PROTECTED]> wrote:
>
> > > Bobbie wrote:
> > > > Hey all, thanks for all your help so far!  I have the following
> > > > function running on a timer every 20 seconds or so.  However, every
> > > > time it runs, my user interface for this program (an EditText box and
> > > > a submit Button) freezes until the HttpPost is finished.  Is there a
> > > > way for me to run this function "in the background" or something so it
> > > > doesn't freeze the interface?  Is there a more efficient way to do
> > > > what I'm trying to do here?  The "chatscreen" variable is a TextView.
>
> > > Yes, run it in another thread --- look up java.lang.Thread. Be aware
> > > that methods in another thread can't call anything in the UI directly,
> > > though; look up Handler.
>
> > > void doSomethingInBackground()
> > > {
> > >   /* Here we're in the UI thread. */
> > >   final Handler handler = new Handler();
> > >   Thread thread = new Thread()
> > >   {
> > >     public void run()
> > >     {
> > >        /* Here we're in the background thread. */
> > >        /* perform blocking operation here */
> > >        handler.post(
> > >          new Runnable()
> > >          {
> > >             public void run()
> > >             {
> > >               /* Back in the UI thread again. Tell the user we're
> > >                * finished. */
> > >             }
> > >          }
> > >        );
> > >     }
> > >   };
>
> > >   /* Start background thread, don't wait (will return immediately). */
> > >   thread.start();
>
> > > }
>
> > > If you think the syntax is nasty, you're not the only one. Bear in mind
> > > that your activity may have finished by the time the thread completes.
> > > Also, if you're going to do this a lot, you'll want to reuse the Handler
> > > and Thread objects.
>
> > > --
> > > David Given
> > > [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to