Make dialog appear on order

梦想的初衷 提交于 2019-12-25 19:36:16

问题


I have a service running on background then when it's triggered by an action it send broadcast to activity when the activity receive this broadcast is shows a dialog , the problem is when the service is triggered two or three...etc times on the same time the activity shows three dialog on top of each other (dialog3 is on top of dialog2 on top of dialog1) I need the dialog to appear on the same order on which they are triggered like (dialog1 is on top of dialog2 is on top of dialog3 )


回答1:


you better stop those 2 and 3 dialog from showing until the first one is finished. you can do it by some condition like below: (more like a psudo code)

 public void processBroadcast(BroadcastModel broadcastModel)
 {
  if(!Const.isAnyDialogShowing)
  {
    CustomDialog dialog=new CustomDialog(broadcastModel);
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            Const.isAnyDialogShowing = false;
            if(broadcastList.size > 0)
            {
               broadcastModel newBroadcastModel = broadcastList.remove(0);
               processBroadcast(newBroadcastModel);
            }
        }
    });
    Const.isAnyDialogShowing = true;
    dialog.Show();
 }
 else
 {
    broadcastList.add(broadcastModel);
 }
}

this way they will be shown with the same order you want .



来源:https://stackoverflow.com/questions/46389553/make-dialog-appear-on-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!