[android-developers] Re: While Loop Stall the rest of the program

2010-09-27 Thread Clover
Hello ArcDroid,

>From my experience, the design concept should be as follow:

We will have 2 threads:

Main Thread will provide a call back for Image Thread to set image to
ImageView.
Image Thread will download/ load the bitmap, then use the call back to
set Bitmap to ImageView.

The call back can be either a method/ function in Main Thread that's
wrapped by runOnUiThread or implemented by Handler of Main Thread.

You can also try to update the ImageView in runOnUiThread, but that's
not a good design, however, it will work.

BR,
Nam

On Sep 26, 2:45 pm, ArcDroid  wrote:
> Hello,
> I am trying to load a picture, then run a while loop.  The problem is
> that the program runs the while loop and doesn't load the pictures
> until the loop has finished.  Any help is appreciated.
> Thanks
> Jake

-- 
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


[android-developers] Re: Ending a Thread Safely

2010-09-28 Thread Clover
Hi Stuart,

Can you determine whether the life cycle of the thread is bound to
which? The SurfaceView or the Activity,
I think the common control should have a callback to let you know that
its life cycle is come to an end (onDestroyed or onSurfaceDestroyed),
you can try to join the Thread at that time, and make sure you have a
well control Thread( extends Thread and define some variable to
control the run()), stop it and join it will help you let the Thread
end safely, as it will have no call back to the object bind the thread
when the object is destroyed.

I cannot provide a sample code, but the concept should be:

SafeThread extends Thread {

boolean stop = false

run() {
while (!stop)
...
}

stop(){
stop = true;
}

}

and

onDestroyed() {
safeThread.stop();
safeThread.join();
}

BR,
Nam

On Sep 28, 11:33 pm, Stuart  wrote:
> I've found lots of great tutorial on starting a thread, however what's
> the best way to close a thread that's using a SurfaceView in a game
> loop and set a new view? Could you provide some sample code?

-- 
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