Welcome to the wonderful world of multithreading. 

You are doing your login work on the main UI thread, which is thus prevented
from being able to show the updates to the screen. You have to find a way to
do the login() work on a separate thread. There are several articles about
multithreading in the Android SDK documentation, but in general the easiest
thing to do that I've found so far is to create a Handler in onCreate(), do
the login() there, then post to your TextView the "Done" message when the
login() returns. Be warned, though--the rest of onCreate() will continue to
execute while the login() is happening, so that may create some other
problems for you later, depending on what you're doing. A CountDownLatch of
1 can be your friend here, as well.

For lots more details about Java threading in general, I highly recommend
Brian Goetz's "Java Concurrency in Practice". (Full disclosure: he's a buddy
of mine, but it's still a good book, despite his choice in friends. ;-) )

Ted Neward
Java, .NET, XML Services
Consulting, Teaching, Speaking, Writing
http://www.tedneward.com

> -----Original Message-----
> From: android-developers@googlegroups.com [mailto:android-
> develop...@googlegroups.com] On Behalf Of Robin van Leeuwen
> Sent: Friday, May 21, 2010 3:06 AM
> To: Android Developers
> Subject: [android-developers] Problem flushing text to screen.
> 
> I have a problem with showing text on the screen before an action is
> taken. I have a function "login()" which takes quite a while, and i
> want
> to display the string "Loggin in..." before this function starts doing
> it's
> work.
> 
> The problem is that the text "Logging in..." is not displayed until
> the
> login() function finishes. And so only "Done..." is displayed.
> 
> ----CODE----
>    public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
> 
>         TextView statusbar = (TextView) findViewById(R.id.statusbar);
> 
>         statusbar.setText("Logging in...");
>         login();
>         statusbar.setText("Done...");
>      }
> 
> How can I flush the IO so the "Logging in..." string is displayed
> before the login() function starts doing it's work?
> 
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-
> develop...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to