Greetings.
How can I send two parameters into a thread and run methods when the user pushes buttons on the display. Having my variables in the UI thread didn't work and were erased when the UI thread randomly restarts.
UI T开发者_JS百科hread ______________ Other Thread
User presses button -------> Run Method
Cheers.
I think you should just define listeners for your buttons. And those listeners should in turn, launch threads with the paremeters you want, to perform other tasks, while keeping the UI available and responsible to the user again, while those threads are performed. You need something like this:
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
Bitmap b = loadImageFromNetwork();
mImageView.setImageBitmap(b);
}
}).start();
}
This example was taken from the Android Developers Blog, where you can get other helpful information and hints.
Have a look at this blog article. It describes how to keep a thread working across screen rotation.
精彩评论