我的用例是,無論何時用戶鍵入某個EditText,輸入數據都會用於在後臺執行操作。這些操作可能需要足夠長的時間才能導致ANR。如果操作足夠準確,@TextChange和@Background一起工作正常。但是操作需要足夠長的時間,以便用戶輸入更多的數據,我將遇到線程問題,因爲將有多個後臺任務將命令更新相同的UI組件。如何使用AndroidAnnotations取消@Background任務
我想我通過AsyncTask API實現了想要的行爲,但也想尋找基於AndroidAnnotations的解決方案,因爲它簡化了代碼。順便提一下,
下面是一些代碼片段,希望能夠說明我的觀點。感謝您至少閱讀,評論/回答感謝:)
@TextChange
void onUserInput(...) {
// This will start a new thread on each text change event
// thus leading to a situation that the thread finishing
// last will update the ui
// the operation time is not fixed so the last event is
// not necessary the last thread that finished
doOperation()
}
@Background
void doOperation() {
// Sleep to simulate long taking operation
Thread.sleep(6000);
updateUi()
}
@UiThread
void updateUi() {
// Update text field etc content based on operations
}
UPDATE:這是不可能的那一刻,見下文天」的答案。
感謝關於AA進度的更新。我會將你的答案設定爲接受。 – kaskelotti 2014-02-04 10:02:20
歡迎。只是爲了完整性,最後一個版本是3.0.1。在android上保持搖滾! – mircobabini 2014-02-05 11:42:20