ActionQueue 允许你一个一个的执行任务。
导入:
allprojects { repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } jcenter() } }
加依赖:
compile 'in.srain.cube:action-queue:1.0.1'
创建 action:
String[] messageList = new String[]{ "message 1", "message 2", "message 3", }; for (int i = 0; i < messageList.length; i++) { String message = messageList[i]; PopDialogAction action = new PopDialogAction(message); mActionQueue.add(action); }
处理 action:
class PopDialogAction extends ActionQueue.Action<String> { public PopDialogAction(String badge) { super(badge); } @Override public void onAction() { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); Dialog dialog = builder.setMessage(getBadge()).show(); // notify action is done, and next aciton will be executed dialog.setOnDismissListener(mOnDismissListener); } }
action 执行完之后通知提醒:
DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mActionQueue.notifyActionDoneThenTryToPopNext(); } };