Skip to content

arch(navigation): support generating raw Intents#21112

Open
david-allison wants to merge 4 commits into
ankidroid:mainfrom
david-allison:destination-3
Open

arch(navigation): support generating raw Intents#21112
david-allison wants to merge 4 commits into
ankidroid:mainfrom
david-allison:destination-3

Conversation

@david-allison
Copy link
Copy Markdown
Member

@david-allison david-allison commented May 20, 2026

Note

Assisted-by: Claude Opus 4.7

Purpose / Description

When extracting widgets to a submodule, we have some pendingIntent usages. navigate() can't be used and instead a raw Intent is required, but we do not want the navigation framework to expose Destionation.toIntent() by default.

val remoteViews = RemoteViews(context.packageName, R.layout.widget_add_note)
val intent = NoteEditorLauncher.AddNote().toIntent(context)
val pendingIntent = PendingIntentCompat.getActivity(context, 0, intent, 0, false)
remoteViews.setOnClickPendingIntent(R.id.widget_add_note_button, pendingIntent)
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews)

Fixes

Approach

We offer a gated method to allow this escape hatch, using my favourite feature: context parameters.

The definitions allow this code to work as expected, while destination.toIntent() is still undefined.

val intent = with(DeferredNavigation) { destination.toIntent() }`

How Has This Been Tested?

commit 1

Screenshot 2026-05-20 at 23 21 50

commit 2

Not necessary - code convention only

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

The Android Studio sidebar shows 'kotlin' instead of 'java+kotlin'
Rarely, a raw intent is required (PendingIntent, TaskStackBuilder,
ShortcutInfo etc...)

This is gated on `DeferredNavigation` to encourage callers to use
`navigate`

Test classes implement the interface for brevity

Part of 20737

Assisted-by: Claude Opus 4.7
As a context parameter, it was inside a `Fragment` which caused
ambiguity. It's better as an extension method
Useful extension method to support a `Destination`

Assisted-by: Claude Opus 4.7
@criticalAY criticalAY added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Second Approval Has one approval, one more approval to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants