Skip to content
Commitwise
Menu
Android Development

App Links, widgets and shortcuts

Open the right screen from web links with verified Android App Links and a Digital Asset Links file, route incoming intents safely, build home screen widgets with Jetpack Glance that read local data and handle taps, update them within the system's limits, and add static, dynamic and pinned app shortcuts.

advanced

The core idea with one simple example.Step by step, with more examples and exercises.A cheat sheet: key APIs, gotchas and trade-offs.Internals, trade-offs and production pitfalls.

The recipe app’s newsletter links to https://recipes.example.com/r/42. On Android 12 and newer, the link opens in the browser instead of the app, even though the app declares an intent filter for it. The new home screen widget shows yesterday’s dinner until the user opens the app, and a long-press on the app icon offers nothing useful. Meanwhile a security review found that a link like /account/delete?confirm=1 deletes the account without asking.

Users reach an Android app from many places besides its icon: links, widgets, app shortcuts. Each has its own rules about verification, process lifetime and update limits. This lesson covers the three you’ll meet in almost every senior Android role.

New to some of these? Open what you need, or skip ahead.

Basics:What is a deep link?

A deep link opens a specific screen inside an app: a recipe, an order, a chat. On Android, links arrive as an intent with a URI (intent.data), matched against intent filters in the manifest. See deep linkDeep linkA URL that opens a specific screen inside an app, from an email, a notification, a QR code or another app.Open in glossary → and the Navigation lesson.

Basics:What is an app widget?

An app widget is a small view of your app on the home screen. It isn’t a running copy of the app: the launcher (a separate app) shows a RemoteViews description that your app provides, and your code runs only when the widget needs to be updated or is tapped.

Part Not started

Widgets and app shortcuts

Widgets with Jetpack Glance. Glance lets you write a widget with a Compose-like API: Column, Text, Button. Under the hood it becomes RemoteViews, the limited set of views a launcher can show for another app. Three rules follow:

  • Read local data. The widget’s code runs briefly, in the background. It reads what the app saved (Room, DataStore) and shows it. It shouldn’t wait for the network.
  • The app pushes updates. When the data changes (the user plans a new dinner), the app tells the widget to update. The built-in periodic update can’t be more often than every 30 minutes; for scheduled refreshes, use WorkManager.
  • Taps run actions. A button can run a small piece of code (an ActionCallback) without opening the app, or open a specific screen.

App shortcuts appear when the user long-presses the app icon: “New recipe”, “Shopping list”. There are three kinds:

  • Static: declared in XML, always the same.
  • Dynamic: created in code, like “Continue: Lasagna” for the last recipe opened.
  • Pinned: the user puts them on the home screen as their own icons.

Each shortcut opens the app with an intent, often the same deep link the website uses.

Glance (GlanceAppWidget + GlanceAppWidgetReceiver) composes RemoteViews from a Compose-style tree; provideGlance loads data then calls provideContent; the session ends after a short time, so long work belongs in WorkManager. Update strategies: the app calls update()/updateAll() after data changes; periodic refresh via WorkManager (respecting battery; updatePeriodMillis has a 30-minute floor and wakes the device); per-instance state with PreferencesGlanceStateDefinition or your own store; responsive layouts via SizeMode.Responsive. Interactions: actionRunCallback<T>() (runs in a short-lived background context), actionStartActivity with a deep link, or actionStartService/broadcast; checkbox and switch components support compound buttons on Android 12+. Widget previews (generated previews on Android 15) and configuration activities improve discovery. App shortcuts: static in res/xml/shortcuts.xml (with capability bindings for Assistant), dynamic with ShortcutManagerCompat.pushDynamicShortcut (rate-limited, ranked, a few visible), pinned via requestPinShortcut; disable shortcuts whose target disappears instead of deleting pinned ones. All of them enter the app through intents, so they share the deep-link router and its validation.

class TonightWidget : GlanceAppWidget() {
    override suspend fun provideGlance(context: Context, id: GlanceId) {
        val recipe = RecipeStore.from(context).tonight()            // local data only: Room or DataStore
        provideContent {
            GlanceTheme {
                Column(GlanceModifier.fillMaxSize().background(GlanceTheme.colors.surface).padding(12.dp)) {
                    if (recipe == null) {
                        Text("Plan tonight's dinner")
                    } else {
                        Text(recipe.title, style = TextStyle(fontWeight = FontWeight.Bold))
                        Button(
                            text = if (recipe.cooked) "Cooked" else "Mark cooked",
                            onClick = actionRunCallback<MarkCookedAction>(actionParametersOf(RecipeIdKey to recipe.id)),
                        )
                    }
                }
            }
        }
    }
}

val RecipeIdKey = ActionParameters.Key<Long>("recipeId")

class MarkCookedAction : ActionCallback {
    override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
        RecipeStore.from(context).markCooked(parameters[RecipeIdKey] ?: return)
        TonightWidget().update(context, glanceId)                   // redraw with the new state
    }
}

class TonightWidgetReceiver : GlanceAppWidgetReceiver() {
    override val glanceAppWidget: GlanceAppWidget = TonightWidget()
}

// In the app, after the user plans dinner: update every placed widget
suspend fun onDinnerPlanned(context: Context) = TonightWidget().updateAll(context)

// A dynamic shortcut to the last opened recipe
fun pushContinueShortcut(context: Context, recipe: Recipe) {
    val shortcut = ShortcutInfoCompat.Builder(context, "continue-recipe")
        .setShortLabel(recipe.title)
        .setLongLabel("Continue: ${recipe.title}")
        .setIcon(IconCompat.createWithResource(context, R.drawable.ic_recipe))
        .setIntent(
            Intent(Intent.ACTION_VIEW, "https://recipes.example.com/r/${recipe.id}".toUri())
                .setPackage(context.packageName)                    // same route as App Links
        )
        .build()
    ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
}
  • provideGlance reads tonight’s recipe from local storage, then describes the widget with Column, Text and Button.
  • actionRunCallback<MarkCookedAction> runs onAction when the button is tapped: it saves the change and calls update, so the widget redraws with “Cooked”. The app doesn’t open.
  • updateAll is called by the app whenever tonight’s dinner changes, so every widget on the home screen shows the new recipe right away.
  • The shortcut opens the recipe through the same https link the website uses, so it goes through the same navigation and validation.

Predict the output

A team sets android:updatePeriodMillis="60000" in the widget's info XML to refresh a stock price every minute. How often does the widget actually update?

Production puzzles

Spot the bugA widget that shows nothing on slow networks

Tap the line with the bug.

class WeatherWidget : GlanceAppWidget() {
    override suspend fun provideGlance(context: Context, id: GlanceId) {
        val forecast = WeatherApi.create().forecast(city = "Belgrade")   // network call
        provideContent {
            Text("${forecast.temperature}° ${forecast.summary}")
        }
    }
}

Exercisehard

Design the entry points

A habit tracker wants: a widget with today’s habits and check-off buttons, a “Log water” shortcut and Assistant phrase, links from reminder emails, and notifications that open the right habit. Sketch the Android architecture so logic isn’t duplicated.

›

All four entry points end in either “show this habit” or “log this habit”. Where should those two operations live?

SolutionTry it yourself first
  • One domain layer (HabitRepository, LogHabitUseCase) used by the app, the widget actions, workers and notification actions.
  • One router for “show” entry points: App Links (/h/{id}), shortcuts and notifications all use the same https URIs handled by Navigation Compose deep links, with validation and an auth guard.
  • “Log” entry points (widget button, shortcut, Assistant via shortcuts.xml capabilities, notification action) call the same use case: ActionCallback for the widget, a small trampoline-free activity or a BroadcastReceiver + WorkManager for notification actions.
  • Widget data comes from Room through the repository; the app calls updateAll after any change; a daily WorkManager job rolls over at midnight.
  • Idempotency: logging from several places (double taps, retried actions) uses an id per log entry, so duplicates don’t count twice.
Exerciseeasy

Add a static shortcut

Add a static “Shopping list” shortcut that opens https://recipes.example.com/shopping. What files change?

›

Static shortcuts are declared in an XML resource referenced from the launcher activity.

SolutionTry it yourself first

res/xml/shortcuts.xml:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut
        android:shortcutId="shopping-list"
        android:enabled="true"
        android:icon="@drawable/ic_cart"
        android:shortcutShortLabel="@string/shortcut_shopping_short"
        android:shortcutLongLabel="@string/shortcut_shopping_long">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.example.recipes"
            android:data="https://recipes.example.com/shopping" />
    </shortcut>
</shortcuts>

And in the manifest, inside the launcher activity:

<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />

The shortcut uses the same link as the website, so the app’s deep-link routing opens the shopping list.

  • Glance: GlanceAppWidget + receiver; provideGlance loads local data then provideContent; short sessions, so long work in WorkManager.
  • Updates: app-driven update/updateAll after data changes; WorkManager for schedules; updatePeriodMillis floor 30 min.
  • Interactions: actionRunCallback, actionStartActivity with deep links; per-instance state; SizeMode.Responsive; generated previews (Android 15).
  • Shortcuts: static (shortcuts.xml, Assistant capabilities), dynamic (pushDynamicShortcut, rate-limited), pinned (requestPinShortcut; disable, don’t delete).
  • Every entry point goes through the same validated router and domain layer.

Check this part

  1. Where should a widget get its data?

  2. What is the minimum for updatePeriodMillis?

  3. How should a widget button that logs a habit work?

  4. A pinned shortcut's target recipe was deleted. What should the app do?

Jetpack Glance builds widgets with a Compose-like API that becomes RemoteViews. Widgets read local data (Room, DataStore) and never wait on the network; updates come from the app after data changes or from WorkManager, because updatePeriodMillis can't go below 30 minutes. Taps run ActionCallbacks or open activities. App shortcuts come in three kinds: static (manifest), dynamic (ShortcutManagerCompat) and pinned; they open the app through deep links.

Key takeaways

  • App Links need an autoVerify intent filter and a matching assetlinks.json on the website.
  • Treat links as untrusted: validate, and only navigate.
  • Glance widgets read local data and are updated by the app; they aren’t live views.
  • Shortcuts and widgets enter the app through the same deep links.
  • Use the Play app signing fingerprint and verify with pm get-app-links.
  • Separate fetching (WorkManager) from widget rendering; respect update limits.
  • Route every entry point through one validated router and shared domain logic.
  • Plan shortcuts’ lifecycle: rate limits, ranking, disabling pinned ones.

Finished this page?Nice work, this page is complete!

Mark it as done to track your progress. It's saved in this browser, no account needed.

Its cards are now in your Bites review ⚡
Esc

Type to search the whole site.