私のアプリはメッセージを受信し、それぞれ異なる遅延で複数の返信を1つずつ順番にスケジュールする必要があります。さまざまな遅延を伴う約2000の遅延タスクを持つ最善の方法は何ですか?限られたリソースのためにAndroidが同時に多くのハンドラを実行することはできないようです。遅延が異なる複数のpostDelayedハンドラ(約2.000)
アイデア?
ありがとうございます。
コード簡素化は:
class TimedTask extends TimerTask { //runs every 10 seconds and checks for new contacts in queue to reply to (contacts can go up to 500 ones)
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(SendMessagesService.this);
String contacts = sp.getString("contacts", ""); //queued by another Thread
String contacts_array[] = contacts.split(",");
for (String contact : contacts_array) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
String message = sp.getString("message1",""); //there are different messages with different delays, depending on which were already sent
ReceiveContactsAdapter mDbHelper = new ReceiveContactsAdapter(SendMessagesService.this);
mDbHelper.open();
mDbHelper.sendMessages(message, contact);
mDbHelper.close();
}
}, delay); //delay depends on which message will be sent
}
}
これを解決するためにキューを使用することは可能ですか? – king
他のタスクの遅延時間が異なるため、キューがブロックされている – LoveForDroid
ハンドラを使用して(機能しない)コードを入力して、達成したいアイデアを得てください。 – dipdipdip