https://kotlinlang.org logo
#splitties
Title
# splitties
s

Sergio Crespo Toubes

03/08/2021, 12:19 PM
Hello, how can i create a pendingIntent with extrasSpecs? Thanks
l

louiscad

03/08/2021, 12:38 PM
Use
intent()
then
toPendingXxx()
from the intents module @Sergio Crespo Toubes
Edited my message, it depends from what the component is.
s

Sergio Crespo Toubes

03/08/2021, 12:39 PM
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

louiscad

03/08/2021, 12:40 PM
Yes, it's alright.
s

Sergio Crespo Toubes

03/08/2021, 12:41 PM
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

louiscad

03/08/2021, 12:44 PM
You can do
MainActivity.intent
for that (granted the
companion object
is an
ActivityIntentSpect
s

Sergio Crespo Toubes

03/08/2021, 12:47 PM
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

louiscad

03/08/2021, 1:03 PM
@Sergio Crespo Toubes Your snippet is wrong, your are instantiating a new
MainActivity
. Replace
MainActivity()
with
MainActivity
s

Sergio Crespo Toubes

03/08/2021, 1:15 PM
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

louiscad

03/08/2021, 1:17 PM
Yes, don't forget to set the flags if needed
s

Sergio Crespo Toubes

03/08/2021, 1:17 PM
i was trying to open MainActivity from notification, but yes i am going set flags
thanks for all
🙂 1
8 Views