Hello, how can i create a pendingIntent with extra...
# splitties
s
Hello, how can i create a pendingIntent with extrasSpecs? Thanks
l
Use
intent()
then
toPendingXxx()
from the intents module @Sergio Crespo Toubes
Edited my message, it depends from what the component is.
s
i have this `
Copy code
val intent = Intent(this, MainActivity::class.java).apply {
            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
        }.putExtra(
            MAIN_DESTINATION_EXTRA, MainDestination.Revision
        )
        val pendingIntent = intent.toPendingActivity()
but i am just using
toPendingActivity
from splitties
l
Yes, it's alright.
s
ah ok i was looking something like this
Copy code
Intent { intentSpec, extrasSpec -> // Magic happens here!
            extrasSpec.showGreetingToast = isUserPolite
            extrasSpec.optionalExtra = intentSpec.someText
        }.toPendingActivity()
thanks
l
You can do
MainActivity.intent
for that (granted the
companion object
is an
ActivityIntentSpect
s
Copy code
MainActivity.ExtrasSpec.mainDestinationExtra = MainDestination.Revision
val pendingIntent = MainActivity().intent.toPendingActivity()
1
its truth thanks @louiscad i didnt see about
companion object
of BundleSpec
l
@Sergio Crespo Toubes Your snippet is wrong, your are instantiating a new
MainActivity
. Replace
MainActivity()
with
MainActivity
s
oh ok done i think
Copy code
val pendingIntent = MainActivity.intent().toPendingActivity()
MainActivity
Copy code
internal companion object : ActivityIntentSpec<MainActivity, ExtrasSpec> by activitySpec(ExtrasSpec)
👍 1
l
Yes, don't forget to set the flags if needed
s
i was trying to open MainActivity from notification, but yes i am going set flags
thanks for all
🙂 1