Put extra depending on the pressed shortcut

112 Views Asked by At

My Android app has 3 shortcuts. Depending on which shortcut was clicked, a message is sent via putExtra. The code is shown below.

val shortcutManager = getSystemService(
        context,
        ShortcutManager::class.java
)

val a: Intent
val b: Intent
val c: Intent

val mainIntent = Intent(Intent.ACTION_VIEW, null, context, Class1::class.java)

a = mainIntent
a.putExtra( "THIS_IS_A",
        Class2::class.java.name
)

b = mainIntent
b.putExtra( "THIS_IS_B",
        Class3::class.java.name
)

c = mainIntent
c.putExtra("THIS IS C",
        Class4::class.java.name
)
val shortcutA = ShortcutInfo.Builder(context, "shortcutId")
        .setShortLabel("a")
        .setLongLabel("a")
        .setIcon(Icon.createWithResource(context, icon))
        .setIntent(a)
        .build()
        ...
val shortcutC = ShortcutInfo.Builder(context, "shortcutIdC")
        .setShortLabel("c")
        .setLongLabel("c")
        .setIcon(Icon.createWithResource(context, icon))
        .setIntent(c)
        .build()
shortcutManager!!.dynamicShortcuts = listOf(shortcutA, ..., shortcutC)

In this case, I am trying to send a unique message using putExtra by clicking on a certain shortcut, so that in the class where I send this data, depending on the value, to perform actions, but in this case only the last putExtra is always sent, i.e. "THIS_IS_C". Please help me figure out how by clicking on a certain element the necessary data was sent, i.e. by clicking on the first shortcut "THIS_IS_A" was sent, and by clicking on the third shortcut "THIS_IS_C" was sent?

0

There are 0 best solutions below