私のユースケースは、ユーザーがEditTextを入力するたびに、入力データがバックグラウンドで操作を実行するために使用されることです。これらの操作は、ANRを引き起こすのに十分な時間がかかる場合があります。@TextChangeと@Backgroundは、操作が十分に迅速に行われていれば正常に機能します。ただし、操作には十分な時間がかかるため、ユーザーがより多くのデータを入力すると、同じUIコンポーネントの更新をコマンドする複数のバックグラウンドタスクが発生するため、スレッドの問題が発生します。
AsyncTask APIを使用して目的の動作を実現したと思いますが、コードが大幅に簡素化されるため、AndroidAnnotationsベースのソリューションも探したいと思いました。ちなみに素晴らしいlib。
以下は、私の主張をうまく説明するコードスニペットです。少なくとも読んでくれてありがとう、コメント/回答はありがたいです:)
@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
}
更新:これは現時点では不可能です。以下のDaySの回答を参照してください。