从线程Java / Android返回值 [英] Returning value from thread Java/ Android
本文介绍了从线程Java / Android返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的android类中有以下线程。如何从线程中获取err的值???
I have the following thread in my android class. How can I get the value of err from the thread???
public int method(){
new Thread(new Runnable() {
int err;
@Override
public void run() {
err = device.verify(30, 5, coderChoice, detectModeChoice,
0, listSearch, callbackCmd, MTFPSD.this, matchingScore);
updateView("Finger Captured Successfully", err);
}
}).start();
return err;
}
我希望该值是方法的返回值但是对于生命对我来说,我无法获得价值......
I want the value to be the return value of the method but for the life of me I can't get the value...
推荐答案
您有两种方法可以实现这一目标。
You have two ways of achieving this.
-
坏方式。
创建一个可变对象,如整数的 list ,让Thread(Runnable)写入列表。您可以访问外部类/方法列表中的值。
The bad way. Create a mutable object like a list of integers and let the Thread (Runnable) write into the list. You can access the value in the list in the outer class / method.
使用 Callable
而不是 Runnable
。 可调用
可以返回值
这篇关于从线程Java / Android返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文