Skip to content

A simple Intent wrapper that adds type safety for passing your data between Android activities in Kotlin.

Notifications You must be signed in to change notification settings

akatkov7/SmartIntent

Repository files navigation

SmartIntent

SmartIntent is a simple Intent wrapper that adds type safety for passing your data between Android activities in Kotlin.

A simple example:

SmartIntent.startActivity(this, SomeActivity::class.java, SomeActivity::testString to editText.text.toString)

Basically, this library allows you to specify a custom initialization block for your new activity while allowing you to pass data safely to the new activity.

To execute the code in your startActivity, do this in your SomeActivity:

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

    SmartIntent.unwrapIntent(this)
    // testString is now set in this class to the correct value

    // ...
}

Installation Instructions

This library can be used in your project through Gradle:

Just add the dependency:

dependencies {
    compile 'me.akatkov.smartintent:smartintent:0.4'
}

Coming Soon

There is progress being made on a SmartBundle class as well that will allow you to do a similar thing with Bundle during onSaveInstanceState.

Example:

override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
    super.onRestoreInstanceState(savedInstanceState)
    
    if (savedInstanceState != null) {
        SmartBundle.unwrapBundle(this, savedInstanceState)
        // do any setup now that properties are set
    }
}

override fun onSaveInstanceState(outState: Bundle) {
    super.onSaveInstanceState(outState)

    SmartBundle.saveInstanceState(this, outState, SecondActivity::testString to testString)
}

TODO

  • Decide if init blocks should stay
  • More robust testing
  • Figure out how to upload a pom file on bintray uploads

About

A simple Intent wrapper that adds type safety for passing your data between Android activities in Kotlin.

Resources

Stars

Watchers

Forks

Packages

No packages published