{"id":13498256,"url":"https://github.com/afollestad/inline-activity-result","last_synced_at":"2025-03-29T00:34:11.754Z","repository":{"id":57716568,"uuid":"183301949","full_name":"afollestad/inline-activity-result","owner":"afollestad","description":"Receive Activity results inline, without any boilerplate. Optional coroutines and RxJava support.","archived":true,"fork":false,"pushed_at":"2021-02-21T05:17:52.000Z","size":186,"stargazers_count":316,"open_issues_count":2,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-24T17:47:51.266Z","etag":null,"topics":["activity-results","android","androidx","coroutines","intent","kotlin","rxjava"],"latest_commit_sha":null,"homepage":"https://af.codes","language":"Kotlin","has_issues":false,"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/afollestad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"afollestad","ko_fi":"afollestad"}},"created_at":"2019-04-24T20:27:45.000Z","updated_at":"2024-03-30T07:33:54.000Z","dependencies_parsed_at":"2022-09-26T21:31:38.769Z","dependency_job_id":null,"html_url":"https://github.com/afollestad/inline-activity-result","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Finline-activity-result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Finline-activity-result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Finline-activity-result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afollestad%2Finline-activity-result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afollestad","download_url":"https://codeload.github.com/afollestad/inline-activity-result/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246122259,"owners_count":20726822,"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","androidx","coroutines","intent","kotlin","rxjava"],"created_at":"2024-07-31T21:00:20.913Z","updated_at":"2025-03-29T00:34:11.260Z","avatar_url":"https://github.com/afollestad.png","language":"Kotlin","funding_links":["https://github.com/sponsors/afollestad","https://ko-fi.com/afollestad"],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"## Inline Activity Result\n\n[![Android CI](https://github.com/afollestad/inline-activity-result/workflows/Android%20CI/badge.svg)](https://github.com/afollestad/inline-activity-result/actions?query=workflow%3A%22Android+CI%22)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4679f36623124f4da988e957e545c8df)](https://www.codacy.com/app/drummeraidan_50/inline-activity-result?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=afollestad/inline-activity-result\u0026amp;utm_campaign=Badge_Grade)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n---\n\n## Table of Contents\n\n1. [Core](#core)\n    1. [Gradle Dependency](#gradle-dependency)\n    2. [Usage](#usage)\n2. [Coroutines](#coroutines)\n    1. [Gradle Dependency](#gradle-dependency-1)\n    2. [Usage](#usage-1)\n3. [RxJava](#rxjava)\n    1. [Gradle Dependency](#gradle-dependency-2)\n    2. [Usage](#usage-2)\n\n---\n\n## Core\n\n### Gradle Dependency\n\n[ ![Core](https://img.shields.io/maven-central/v/com.afollestad.inline-activity-result/core?style=flat\u0026label=Core) ](https://repo1.maven.org/maven2/com/afollestad/inline-activity-result/core)\n\n```gradle\ndependencies {\n  ...\n  implementation 'com.afollestad.inline-activity-result:core:0.2.0'\n}\n```\n\n### Usage\n\nYou call `startActivityForResult`, providing the Activity to launch as the generic type. You\nreceive the result in a callback *without* having to override `onActivityResult`. And, you don't \nhave to worry about `requestCode` or `resultCode`.\n\n```kotlin\nclass NewActivity : AppCompatActivity() {\n\n  override fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n\n    val extras = Bundle()\n        .putString(\"some_extra\", \"Hello, World!\")\n\n    startActivityForResult\u003cOtherActivity\u003e(extras) { success, data -\u003e\n      if (success) {\n        toast(\"Got successful result: $data\")\n      }\n    }\n  }\n}\n```\n\n---\n\nThere are multiple variants `startActivityForResult` you can use for different use cases. *All of \nthem allow you to pass an optional `requestCode` parameter, but this should generally be unnecessary.*\n\nFirst, the simplest you can get is just a generic type and the callback.\n\n```kotlin\nstartActivityForResult\u003cOtherActivity\u003e { success, data -\u003e\n    // Do something\n}\n```\n\nSecond, you can provide a `Bundle` of extras to the destination Activity:\n\n```kotlin\nval extras = Bundle()\n    .putString(\"some_extra\", \"Hello, World!\")\nstartActivityForResult\u003cOtherActivity\u003e(extras) { success, data -\u003e\n    // Do something\n}\n    \n```\n\nAnd finally, you can use a full intent. In this variant you do not provide a generic parameter.\n\n```kotlin\nval intent = Intent(Intent.ACTION_VIEW)\n    .setData(\"content://some-uri\".toUri())\nstartActivityForResult(intent) { success, data -\u003e\n  // Do something\n}\n```\n\n---\n\n## Coroutines\n\n### Gradle Dependency\n\n[ ![Coroutines](https://img.shields.io/maven-central/v/com.afollestad.inline-activity-result/coroutines?style=flat\u0026label=Coroutines) ](https://repo1.maven.org/maven2/com/afollestad/inline-activity-result/coroutines)\n\n```gradle\ndependencies {\n  ...\n  implementation 'com.afollestad.inline-activity-result:coroutines:0.2.0'\n}\n```\n\n### Usage\n\nYou can use Kotlin coroutines to get rid of the callback. It of course is a suspend function so it\nmust be called within a coroutine scope.\n\nInstead of `startActivityForResult`, you can use `startActivityAwaitResult`:\n\n```kotlin\nval result: ActivityResult = startActivityAwaitResult\u003cOtherActivity\u003e()\n// use result...\n```\n\n---\n\n## RxJava\n\n### Gradle Dependency\n\n[ ![RxJava](https://img.shields.io/maven-central/v/com.afollestad.inline-activity-result/rxjava?style=flat\u0026label=RxJava) ](https://repo1.maven.org/maven2/com/afollestad/inline-activity-result/rxjava)\n\n```gradle\ndependencies {\n  ...\n  implementation 'com.afollestad.inline-activity-result:rxjava:0.2.0'\n}\n```\n\n### Usage\n\nYou can use RxJava to integrate the Activity launch and result into your streams.\n\nInstead of `startActivityForResult`, you can use `startActivityEmitResult`:\n\n```kotlin\nval disposable = startActivityEmitResult\u003cOtherActivity\u003e()\n  .subscribe { result -\u003e\n     // use result...\n  }\n\n// make sure you dispose of the subscription when your Activity/Fragment goes away\ndisposable.dispose()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafollestad%2Finline-activity-result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafollestad%2Finline-activity-result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafollestad%2Finline-activity-result/lists"}