{"id":20206118,"url":"https://github.com/jaredrummler/blockingdialog","last_synced_at":"2026-01-04T12:03:10.658Z","repository":{"id":57725504,"uuid":"82169693","full_name":"jaredrummler/BlockingDialog","owner":"jaredrummler","description":"Show a dialog from a background thread and wait for a result.","archived":false,"fork":false,"pushed_at":"2017-05-07T00:00:21.000Z","size":108,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-24T11:44:16.474Z","etag":null,"topics":["android","background-thread","dialog"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredrummler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T10:37:59.000Z","updated_at":"2023-09-08T17:21:00.000Z","dependencies_parsed_at":"2022-09-02T03:41:05.042Z","dependency_job_id":null,"html_url":"https://github.com/jaredrummler/BlockingDialog","commit_stats":null,"previous_names":["jrummyapps/blocking-dialog"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FBlockingDialog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FBlockingDialog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FBlockingDialog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FBlockingDialog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredrummler","download_url":"https://codeload.github.com/jaredrummler/BlockingDialog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244159989,"owners_count":20408019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","background-thread","dialog"],"created_at":"2024-11-14T05:21:23.935Z","updated_at":"2026-01-04T12:03:10.581Z","avatar_url":"https://github.com/jaredrummler.png","language":"Java","readme":"## Blocking Dialog\n\nShow a dialog from a background thread and wait for a result. Discussed on StackOverflow [here](http://stackoverflow.com/q/4381296/1048340) and [here](http://stackoverflow.com/q/2028697/1048340).\n\n\u003cimg src=\"https://img.shields.io/badge/API-11%2B-blue.svg?style=flat\" alt=\"API\" /\u003e \u003ca target=\"_blank\" href=\"LICENSE.txt\"\u003e\u003cimg src=\"http://img.shields.io/:license-apache-blue.svg\" alt=\"License\" /\u003e\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/blocking-dialog\"\u003e\u003cimg src=\"https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/blocking-dialog/badge.svg\" alt=\"Maven Central\" /\u003e\u003c/a\u003e \u003cimg src=\"https://img.shields.io/badge/methods-20-e91e63.svg\" /\u003e \u003ca target=\"_blank\" href=\"https://twitter.com/jaredrummler\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/jaredrummler.svg?style=social\" /\u003e\u003c/a\u003e\n\n## Usage\n\n**1.** Create a dialog that extends `BlockingDialogFragment`:\n\n```java\npublic class YesOrNoDialog extends BlockingDialogFragment\u003cString\u003e {\n\n  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {\n    return new AlertDialog.Builder(getActivity())\n        .setMessage(\"Do you like Taylor Swift?\")\n        .setPositiveButton(\"YES\", new DialogInterface.OnClickListener() {\n          @Override public void onClick(DialogInterface dialog, int which) {\n            setResult(\"YES\", false);\n          }\n        })\n        .setNegativeButton(\"NO\", new DialogInterface.OnClickListener() {\n          @Override public void onClick(DialogInterface dialog, int which) {\n            setResult(\"NO\", false);\n          }\n        })\n        .create();\n  }\n}\n```\n\n**2.** Show the dialog from a worker thread using `BlockingDialogManager#showAndWait`:\n\n```java\npublic class MyTask extends AsyncTask\u003cVoid, Void, Void\u003e {\n\n  WeakReference\u003cActivity\u003e weakActivity;\n\n  ...\n\n  @Override protected Void doInBackground(Void... params) {\n\n    ...\n\n    // Need input from the  user.\n    // Show the dialog from the UI thread and wait on this background thread for a result\n    Activity activity = weakActivity.get();\n    String input = BlockingDialogManager.getInstance().showAndWait(activity, new YesOrNoDialog());\n\n    if (input == null) {\n      // user cancelled\n    } else if (input.equals(\"YES\")) {\n      // do something\n    }\n\n    return null;\n  }\n\n}\n```\n\nSee the [demo](demo) project.\n\n## Download\n\nDownload [the latest JAR](https://repo1.maven.org/maven2/com/jaredrummler/blocking-dialog/1.0.0/blocking-dialog-1.0.0.jar) or grab via Gradle:\n\n```groovy\ncompile 'com.jaredrummler:blocking-dialog:1.0.0'\n```\n\n## License\n\n    Copyright 2017 Jared Rummler\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredrummler%2Fblockingdialog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredrummler%2Fblockingdialog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredrummler%2Fblockingdialog/lists"}