All Projects → afollestad → Inline Activity Result

afollestad / Inline Activity Result

Licence: apache-2.0
Receive Activity results inline, without any boilerplate. Optional coroutines and RxJava support.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Inline Activity Result

Awesome Android Kotlin Apps
👓 A curated list of awesome android kotlin apps by open-source contributors.
Stars: ✭ 1,058 (+255.03%)
Mutual labels:  rxjava, coroutines
Mvvm Kotlin Android Architecture
MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit5
Stars: ✭ 1,014 (+240.27%)
Mutual labels:  rxjava, coroutines
Handle Path Oz
Android Library to handle multiple Uri's(paths) received through Intents.
Stars: ✭ 36 (-87.92%)
Mutual labels:  coroutines, intent
RxCoroutineSchedulers
Kotlin Coroutines as RxJava Schedulers 😈
Stars: ✭ 31 (-89.6%)
Mutual labels:  rxjava, coroutines
Kpermissions
A Kotlin library which helps to request runtime permissions in Android.
Stars: ✭ 253 (-15.1%)
Mutual labels:  rxjava, coroutines
Assure
A Kotlin library that makes biometric authentication quick and easy.
Stars: ✭ 55 (-81.54%)
Mutual labels:  rxjava, coroutines
Runtimepermission
Simpliest way to ask runtime permissions on Android, no need to extend class or override permissionResult method, choose your way : Kotlin / Coroutines / RxJava / Java7 / Java8
Stars: ✭ 860 (+188.59%)
Mutual labels:  rxjava, coroutines
Fountain
Android Kotlin paged endpoints made easy
Stars: ✭ 175 (-41.28%)
Mutual labels:  rxjava, coroutines
NewsReader
Android News Reader app. Kotlin Coroutines, Retrofit and Realm
Stars: ✭ 21 (-92.95%)
Mutual labels:  rxjava, coroutines
modern-android
Modern Android Project Skeleton
Stars: ✭ 17 (-94.3%)
Mutual labels:  rxjava, coroutines
Kotlin Cleanarchitecture
This is a sample app that is part of a blog post I have written about how to architect android application using the Uncle Bob's clean architecture and Fernando Cejas Android-CleanArchitecture in Kotlin. Post in Spanish: http://katade.com/clean-architecture-kotlin/
Stars: ✭ 274 (-8.05%)
Mutual labels:  rxjava
Friendbook
📕 "友书" 小说阅读app
Stars: ✭ 275 (-7.72%)
Mutual labels:  rxjava
Rxeasyhttp
本库是一款基于RxJava2+Retrofit2实现简单易用的网络请求框架,结合android平台特性的网络封装库,采用api链式调用一点到底,集成cookie管理,多种缓存模式,极简https配置,上传下载进度显示,请求错误自动重试,请求携带token、时间戳、签名sign动态配置,自动登录成功后请求重发功能,3种层次的参数设置默认全局局部,默认标准ApiResult同时可以支持自定义的数据结构,已经能满足现在的大部分网络请求。
Stars: ✭ 3,021 (+913.76%)
Mutual labels:  rxjava
Xhttp2
💪A powerful network request library, encapsulated using the RxJava2 + Retrofit2 + OKHttp combination.(一个功能强悍的网络请求库,使用RxJava2 + Retrofit2 + OKHttp组合进行封装)
Stars: ✭ 292 (-2.01%)
Mutual labels:  rxjava
Functionalandroidreference
Showcase project of Functional Reactive Programming on Android, using RxJava.
Stars: ✭ 274 (-8.05%)
Mutual labels:  rxjava
Awesome Swoole
A curated list of Swoole
Stars: ✭ 283 (-5.03%)
Mutual labels:  coroutines
Rxandroidble
An Android Bluetooth Low Energy (BLE) Library with RxJava2 interface
Stars: ✭ 3,025 (+915.1%)
Mutual labels:  rxjava
Architecturecomponentsdemo
Kotlin demo project that uses some Android Architecture Components (ViewModel and LiveData) with Dagger 2 and Coroutines
Stars: ✭ 269 (-9.73%)
Mutual labels:  coroutines
Android Jetpack Playground
Pet project for cutting edge Android development with Jetpack
Stars: ✭ 266 (-10.74%)
Mutual labels:  coroutines
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+930.54%)
Mutual labels:  rxjava

Inline Activity Result

Android CI Codacy Badge License


Table of Contents

  1. Core
    1. Gradle Dependency
    2. Usage
  2. Coroutines
    1. Gradle Dependency
    2. Usage
  3. RxJava
    1. Gradle Dependency
    2. Usage

Core

Gradle Dependency

Core

dependencies {
  ...
  implementation 'com.afollestad.inline-activity-result:core:0.2.0'
}

Usage

You call startActivityForResult, providing the Activity to launch as the generic type. You receive the result in a callback without having to override onActivityResult. And, you don't have to worry about requestCode or resultCode.

class NewActivity : AppCompatActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val extras = Bundle()
        .putString("some_extra", "Hello, World!")

    startActivityForResult<OtherActivity>(extras) { success, data ->
      if (success) {
        toast("Got successful result: $data")
      }
    }
  }
}

There are multiple variants startActivityForResult you can use for different use cases. All of them allow you to pass an optional requestCode parameter, but this should generally be unnecessary.

First, the simplest you can get is just a generic type and the callback.

startActivityForResult<OtherActivity> { success, data ->
    // Do something
}

Second, you can provide a Bundle of extras to the destination Activity:

val extras = Bundle()
    .putString("some_extra", "Hello, World!")
startActivityForResult<OtherActivity>(extras) { success, data ->
    // Do something
}
    

And finally, you can use a full intent. In this variant you do not provide a generic parameter.

val intent = Intent(Intent.ACTION_VIEW)
    .setData("content://some-uri".toUri())
startActivityForResult(intent) { success, data ->
  // Do something
}

Coroutines

Gradle Dependency

Coroutines

dependencies {
  ...
  implementation 'com.afollestad.inline-activity-result:coroutines:0.2.0'
}

Usage

You can use Kotlin coroutines to get rid of the callback. It of course is a suspend function so it must be called within a coroutine scope.

Instead of startActivityForResult, you can use startActivityAwaitResult:

val result: ActivityResult = startActivityAwaitResult<OtherActivity>()
// use result...

RxJava

Gradle Dependency

RxJava

dependencies {
  ...
  implementation 'com.afollestad.inline-activity-result:rxjava:0.2.0'
}

Usage

You can use RxJava to integrate the Activity launch and result into your streams.

Instead of startActivityForResult, you can use startActivityEmitResult:

val disposable = startActivityEmitResult<OtherActivity>()
  .subscribe { result ->
     // use result...
  }

// make sure you dispose of the subscription when your Activity/Fragment goes away
disposable.dispose()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].