问题
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