Component used: GlanceAppWidget
Library & Version used: androidx.glance:glance-appwidget:1.0.0-alpha03
In the Row and Column if we have more than 1 button onClick and if we use actionStartActivity and pass the intent and parameters, it will take the last parameter for all buttons.
Example:
In Row, I have 3 buttons for that onClick, I use actionStartActivity and pass the intent and parameters, when I click Button 1 or Button 2, I will get parameters as "Test 3" every time instead of Test 1 or Test 2 as parameter it will return the last parameter for all buttons onClick.
Example Parameters:
Button 1 = "Test 1"
Button 2 = "Test 2"
Button 3 = "Test 3"
Issue Tracker: https://issuetracker.google.com/issues/238793260
IssueTracker : https://issuetracker.google.com/issues/238793260
I think this is happening due to the fact that we request a PendingIntent for each actionStartActivity, and they will get conflated if the underlying intents are the same (as defined by Intent.filterEquals). There is more on this in the class doc for PendingIntent.
For certain forms of actionStartActivity (i.e. the ones defined in this file), this is not an issue because we wrap the intent in a trampoline intent, on which we set a unique Intent data URI. The following works fine:
Row {
Button(
text = "Button 1",
onClick = actionStartActivity<ActionDemoActivity>(
actionParametersOf(
StartMessageKey to "Test 1"
)
)
)
Button(
text = "Button 2",
onClick = actionStartActivity<ActionDemoActivity>(
actionParametersOf(
StartMessageKey to "Test 2"
)
)
)
Button(
text = "Button 3",
onClick = actionStartActivity<ActionDemoActivity>(
actionParametersOf(
StartMessageKey to "Test 3"
)
)
)
}
However, for the form of actionStartActivity that takes an intent directly, we do not wrap it in a trampoline intent.
We could create a unique data field for the user-supplied intent, though that could interfere with their use of the data field. Another option is to document the latter form of actionStartActivity so that users know they must add a unique data field to the intent they supply us with.