Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature proposal] Android intent arguments #53

Closed
arnaudgiuliani opened this issue Feb 15, 2018 · 4 comments
Closed

[Feature proposal] Android intent arguments #53

arnaudgiuliani opened this issue Feb 15, 2018 · 4 comments

Comments

@arnaudgiuliani
Copy link
Member

Hello dear Koin users,

I was talking to people using Koin, about setProperty to help set a Koin property in your app. But an overuse of this feature can lead to putting all your arguments data between activities/fragments in Koin properties, whereas we should respect the Android approach: keep argument data in intents.

I would like to give some "Android extra" help on intent, to help set up arguments on Android and avoid misuse with Koin properties.

I propose a startActivity and withArguments :

startActivity<WeatherDetailActivity> {
            withArguments(
                    PROPERTY_WEATHER_DATE to date,
                    PROPERTY_ADDRESS to address,
                    PROPERTY_WEATHER_ITEM_ID to id)
        }

and on receiving activity or fragment, argument binding:

class WeatherDetailActivity : AppCompatActivity() {

    // Get all needed data
    val address by argument<String>(PROPERTY_ADDRESS)
    val now by argument<Date>(PROPERTY_WEATHER_DATE)
    val id by argument<String>(PROPERTY_WEATHER_ITEM_ID)

This will bind those properties with the underlying intent. This feature is sort of borderline with Koin goals, but I think we are still in "assembling" components subject.

Source: https://github.com/Ekito/koin/blob/0.9.0/android/koin-android/src/main/java/org/koin/android/ext/android/Extras.kt

Sample app with intent arguments: https://github.com/Ekito/koin-samples/blob/master/samples/android-weatherapp-mvvm/

Feature available in Koin 0.9.0-alpha-5.

--

Just put some 👍, other emojis or comments :)

Thanks for your feedback.

@Bodo1981
Copy link

Good idea!

but you only allow serializable arguments which are very slow on android platform.
maybe you could provide multiple types especially parcelable

@arnaudgiuliani
Copy link
Member Author

Good things have been made with Anko intents - https://github.com/Kotlin/anko/wiki/Anko-Commons-%E2%80%93-Intents

@dawidhyzy
Copy link

dawidhyzy commented Feb 15, 2018

I can understand why you made this proposal but don't you feel that this shouldn't be a part of this library?

@arnaudgiuliani
Copy link
Member Author

Yes, That's also why I make a proposal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants