{"id":15484581,"url":"https://github.com/hichamboushaba/suspendactivityresult","last_synced_at":"2025-04-22T15:26:26.562Z","repository":{"id":44431710,"uuid":"427974507","full_name":"hichamboushaba/SuspendActivityResult","owner":"hichamboushaba","description":"A lightweight library for requesting and consuming Activity Results using coroutines.","archived":false,"fork":false,"pushed_at":"2022-02-08T14:38:00.000Z","size":167,"stargazers_count":77,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T04:19:13.632Z","etag":null,"topics":["activity-results","android","coroutines","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hichamboushaba.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-14T16:03:21.000Z","updated_at":"2025-01-28T08:37:38.000Z","dependencies_parsed_at":"2022-09-06T12:23:13.739Z","dependency_job_id":null,"html_url":"https://github.com/hichamboushaba/SuspendActivityResult","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hichamboushaba%2FSuspendActivityResult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hichamboushaba%2FSuspendActivityResult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hichamboushaba%2FSuspendActivityResult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hichamboushaba%2FSuspendActivityResult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hichamboushaba","download_url":"https://codeload.github.com/hichamboushaba/SuspendActivityResult/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250266305,"owners_count":21402266,"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":["activity-results","android","coroutines","kotlin"],"created_at":"2024-10-02T05:41:21.096Z","updated_at":"2025-04-22T15:26:26.537Z","avatar_url":"https://github.com/hichamboushaba.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Version](https://img.shields.io/maven-central/v/dev.hichamboushaba.suspendactivityresult/suspendactivityresult)](https://repo1.maven.org/maven2/dev/hichamboushaba/suspendactivityresult/)\n\n## SuspendActivityResult\n\nA lightweight library for requesting and\nconsuming [Activity Results](https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract%3CI,O%3E,androidx.activity.result.ActivityResultCallback%3CO%3E))\nusing coroutines, it's usage is as simple as:\n\n```kotlin\nval uri = ActivityResultManager.getInstance().requestResult(\n    contract = GetContent(),\n    input = \"image/*\"\n)\n```\n\nor using the built-in extensions:\n\n```kotlin\nval uri = ActivityResultManager.getInstance().getContent(\"image/*\")\n```\n\nFor more information, check the\narticles: [Part 1](https://dev.to/hichamboushaba/consuming-activity-results-using-coroutines-part-1-2j57)\nand [Part 2](https://dev.to/hichamboushaba/consuming-activity-results-using-coroutines-part-2-54mf)\n\n### Runtime Permissions\n\nThe library offers a utility class for requesting runtime permissions with access to\nthe [shouldShowRequestPermissionRationale](https://developer.android.com/reference/android/app/Activity#shouldShowRequestPermissionRationale(java.lang.String))'s\nvalue:\n\n```kotlin\nval result = PermissionManager.getInstance()\n    .requestPermission(Manifest.permission.ACCESS_COARSE_LOCATION)\nwhen (result) {\n    PermissionGranted -\u003e {\n        // TODO\n    }\n    is PermissionDenied -\u003e {\n        if (result.shouldShowRationale) {\n            // TODO\n        } else {\n            // TODO\n        }\n    }\n}\n```\n\nThis class uses internally `ActivityResultManager.getInstance().requestPermission()`, so everything\nbelow applies to it as well.\n\n### Download\n\n```groovy\nimplementation 'dev.hichamboushaba.suspendactivityresult:suspendactivityresult:0.1.5'\n```\n\nThe default artifact uses [App Startup](https://developer.android.com/topic/libraries/app-startup)\nfor the initialization.\n\nIf you don't want this dependency added, you can use the other variant:\n\n```groovy\nimplementation 'dev.hichamboushaba.suspendactivityresult:suspendactivityresult-no-startup:0.1.5'\n```\n\nAnd initialize the library manually\n\n```kotlin\nclass App : Application() {\n    fun onCreate() {\n        super.onCreate()\n        ActivityResultManager.init(this)\n    }\n}\n```\n\n### Testing\n\n`ActivityResultManager` is an interface, so for better testability, it's recommended to\ninject `ActivityResultManager.getInstance()`\ninto your components, for easier swapping to a fake or mocked implementation for tests.\n\n### Process-death\n\nThe implementation of `requestResult` takes into account process-death scenarios, and keeps track of\nthe pending operation using the\nActivity's [SavedStateRegistry](https://developer.android.com/reference/androidx/savedstate/SavedStateRegistry)\n, which means calling `requestResult` after a process-death, will not re-launch the activity result\ncaller, and instead, it will only register the callback to allow receiving the result. And to make\nthis work as expected, the application need to keep the screen's state across this process-death, to\ncall `requestResult` afterwards, check\nthe [example app](./app/src/main/java/com/hicham/activityresult/files/ExternalFilesViewModel.kt) for\nhow we can implement this\nusing [SavedStateHandle](https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle)\n.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhichamboushaba%2Fsuspendactivityresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhichamboushaba%2Fsuspendactivityresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhichamboushaba%2Fsuspendactivityresult/lists"}