我的代碼有多個線程和Runnable
。我的問題是我改變了Runnable
調用線程中某個變量的值。Android同步線程
在調用之後,我對該變量值進行了檢查,但未檢索到該值。
如何檢索處理後的值?這裏是Runnable
和Thread
代碼:
final Runnable r = new Runnable()
{
public void run()
{
if(flag==true)
onSwipe();
if(SwipeAgain==true)
handler.postDelayed(this, 1000);
}
};
private void onSwipe() {
new Thread() {
public void run() {
String data = null;
decryption_data = null;
encryption_data = null;
SwipeAgain=false;
handler.post(clear_encryption);
try {
data = sreader.ReadCard(15000);
} catch (Exception ex) {
if (ex instanceof TimeoutException) {
return;
} else
CloseSinWave();
}
if (data == null) {
SwipeAgain=true;
encryption_data = sreader.GetErrorString();
if (encryption_data.equalsIgnoreCase("cancel all"))
return;
handler.post(display_encryptiondata);
} else {
encryption_data = "\n" + data;
handler.post(display_encryptiondata);
}.start();
}
SwipeAgain
是處理
,請在您的清單中刪除無關的代碼,使其更易於閱讀 – ben75
確定我刪除了大部分無關的代碼是這更好 – user2401745