{"action":"opened","issue":{"url":"https://api.github.com/repos/afollestad/material-dialogs/issues/705","labels_url":"https://api.github.com/repos/afollestad/material-dialogs/issues/705/labels{/name}","comments_url":"https://api.github.com/repos/afollestad/material-dialogs/issues/705/comments","events_url":"https://api.github.com/repos/afollestad/material-dialogs/issues/705/events","html_url":"https://github.com/afollestad/material-dialogs/issues/705","id":107532883,"number":705,"title":"issue subclassing MaterialDialog and MaterialDialog.Builder","user":{"login":"inteist","id":53954,"avatar_url":"https://avatars.githubusercontent.com/u/53954?v=3","gravatar_id":"","url":"https://api.github.com/users/inteist","html_url":"https://github.com/inteist","followers_url":"https://api.github.com/users/inteist/followers","following_url":"https://api.github.com/users/inteist/following{/other_user}","gists_url":"https://api.github.com/users/inteist/gists{/gist_id}","starred_url":"https://api.github.com/users/inteist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inteist/subscriptions","organizations_url":"https://api.github.com/users/inteist/orgs","repos_url":"https://api.github.com/users/inteist/repos","events_url":"https://api.github.com/users/inteist/events{/privacy}","received_events_url":"https://api.github.com/users/inteist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-21T15:06:17Z","updated_at":"2015-09-21T15:06:17Z","closed_at":null,"body":"I need to make sure dialogs do not overlap each other (they can with the current implementation if invoked in a row). I managed this in my own code but this did not look like the right solution. So I decided to extend MaterialDialog. I was going to do a pull request but I wasn't sure how relevant this would be to others since and I wanted to test it a bit and to my surprise there seems to be a problem with what seems like 100% legit (and very simple) subclassing implementation so I suspect the problem lies somewhere deeper in the library this is why I file it as an issue. I apologize in advance if that is something I overlooked but as you will see the implementation is pretty simple and straightforward and I can't imagine how it could be the subclassing issue. \r\n\r\nHere's the code:\r\n\r\n```java\r\npackage info.androidz.horoscope.UI.element.dialog;\r\n\r\nimport android.content.Context;\r\nimport android.content.DialogInterface;\r\nimport android.support.annotation.NonNull;\r\n\r\nimport com.afollestad.materialdialogs.MaterialDialog;\r\nimport com.comitic.android.util.CLog;\r\n\r\n/**\r\n * Created by max on 9/17/15.\r\n */\r\npublic class OneAtATimeMaterialDialog extends MaterialDialog {\r\n\r\n    private static boolean hasActiveDialogOnScreen = false;\r\n\r\n    protected OneAtATimeMaterialDialog(MaterialDialog.Builder builder) {\r\n        super(builder);\r\n    }\r\n\r\n\r\n    @Override\r\n    public void show() {\r\n        if (!hasActiveDialogOnScreen) {\r\n            hasActiveDialogOnScreen = true;\r\n            super.show();\r\n        }\r\n    }\r\n\r\n\r\n\r\n//             ____        _ _     _\r\n//            |  _ \\      (_) |   | |\r\n//            | |_) |_   _ _| | __| | ___ _ __\r\n//            |  _ <| | | | | |/ _` |/ _ \\ '__|\r\n//            | |_) | |_| | | | (_| |  __/ |\r\n//            |____/ \\__,_|_|_|\\__,_|\\___|_|\r\n//\r\n\r\n    public static class Builder extends MaterialDialog.Builder {\r\n\r\n        public Builder(@NonNull Context context) {\r\n            super(context);\r\n\r\n            dismissListener(new OnDismissListener() {\r\n                @Override\r\n                public void onDismiss(DialogInterface dialog) {\r\n                    hasActiveDialogOnScreen = false;\r\n                }\r\n            });\r\n        }\r\n\r\n        @Override\r\n        public MaterialDialog.Builder dismissListener(@NonNull final OnDismissListener listener) {\r\n\r\n            return super.dismissListener(new OnDismissListener() {\r\n                @Override\r\n                public void onDismiss(DialogInterface dialog) {\r\n                    hasActiveDialogOnScreen = false;\r\n                    listener.onDismiss(dialog);\r\n                }\r\n            });\r\n        }\r\n\r\n\r\n        @Override\r\n        public MaterialDialog build() {\r\n            super.build();\r\n            OneAtATimeMaterialDialog d = new OneAtATimeMaterialDialog(this);\r\n            return d;\r\n        }\r\n\r\n\r\n        @Override\r\n        public MaterialDialog show() {\r\n            if (!hasActiveDialogOnScreen) {\r\n                hasActiveDialogOnScreen = true;\r\n                return super.show();\r\n            }\r\n            else {\r\n                CLog.w(\"MD - has active dialog showing - not showing and returning null\");\r\n                return null;\r\n            }\r\n        }\r\n    }\r\n\r\n\r\n\r\n}\r\n\r\n```\r\n\r\n### Stack trace\r\n\r\n```\r\njava.lang.RuntimeException: Unable to start activity ComponentInfo{PACKAGE.ACTIVITY}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.\r\n\r\n```\r\n at com.afollestad.materialdialogs.MaterialDialog.(MaterialDialog.java:91)\r\n at MYPACKAGE.UI.element.dialog.OneAtATimeMaterialDialog.(OneAtATimeMaterialDialog.java:18)\r\n```\r\n\r\nthe line `91` in the lib is:\r\n```\r\nDialogInit.init(this);\r\n```\r\n\r\nI am using the 0.7.8.0 and I checked out the `v0.7.8.0` and given the err message it does all make sense that this would be the problematic line.\r\n\r\n\r\n\r\n\r\n### NOTES:\r\nIn our internal testing we did not encounter any problems. Only when we released the app to the wild we started seeing this. But it is not very rare. We had a LOT of crash reports. Devices/OS seem to vary so this is not device/os specific. Not sure why we did not see this in our internal testing.\r\n\r\nHope you can shed some light on this and hopefully we can get it fixed quickly. \r\n\r\nLet me know if you want me to do a pull request, although it might be easier if you just incorporate this into the lib. I think it is very useful and saves quite a bit of code while actually using the lib in an app since you don't have to track whether there is another dialog showing already. And you can always have the default behavior by instantiating the default class."}}