Skip to content
Property binding for Android Bundle arguments.
Kotlin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
argument-delegate
gradle
sample
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Argument Delegate

Property binding for Android Bundle arguments. Written for simple bundle unpacking for Kotlin users.

Download

Download

Add repository to your root build.gradle

repositories {
    jcenter()
}
dependencies {
  implementation 'com.idapgroup:argument-delegate:latest-version'
}

Usage sample

class ExampleActivity : Activity {

    val userName: String by argumentDelegate()
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // your activity setup code
        Log.d("ExampleActivity", "userName - $userName")
    }

}

Remember: Bundled argument name must have the same name as property have. For current example:

val bundle = Bundle().apply {
    putString("userName", "John")
}

Additional info

argumentDelegate is an extension function for Fragment and Activity. If you want to use it out of the Activity/Fragment then you should implement argumentWrapper block. Example:

class Example {
    private lateinit var bundle: Bundle
    private val wrapper = { a: Example -> a.bundle }
    val userName: String by argumentDelegate(wrapper)
}
You can’t perform that action at this time.