Android Jetpack Compose: How to Prevent a Pinned Dynamic Shortcut from Getting Updated?

 In Android Jetpack Compose, dynamic shortcuts can be updated automatically by the system when the associated data changes. If you want to prevent a pinned dynamic shortcut from getting updated, you can use a unique identifier for the shortcut that remains constant. Here's how you can do it:


1. **Specify a unique `id` for the dynamic shortcut**: When creating a dynamic shortcut, provide a unique identifier for it using the `setLongLived(true)` method. This indicates that the shortcut should not be updated based on changes in associated data.


```kotlin

DynamicShortcutManagerCompat(context).reportShortcut(

    ShortcutInfoCompat.Builder(context, "unique_id") // Use a unique ID here

        .setShortLabel("Shortcut Label")

        .setIntent(/* your intent here */)

        .setLongLived(true) // Prevent automatic updates

        .build()

)

```


2. **Use a constant ID**: Ensure that the `id` you specify remains constant for this particular shortcut. It shouldn't change regardless of changes in associated data.


3. **Avoid changing the shortcut's attributes**: If you don't want the shortcut to get updated, avoid changing its attributes, such as the label, icon, or intent, after it has been pinned.


By setting a unique ID and making sure it remains constant, you can prevent the system from automatically updating the pinned dynamic shortcut. This is useful when you want to maintain a consistent shortcut experience for the user.

Comments

Popular posts from this blog

bad character U+002D '-' in my helm template

GitLab pipeline stopped working with invalid yaml error

How do I add a printer in OpenSUSE which is being shared by a CUPS print server?