(#) A should not be attached to an destination
!!! WARNING: A should not be attached to an destination
This is a warning.
Id
: `DeepLinkInActivityDestination`
Summary
: A should not be attached to an destination
Severity
: Warning
Category
: Correctness
Platform
: Android
Vendor
: Android Open Source Project
Identifier
: androidx.navigation.runtime
Feedback
: https://issuetracker.google.com/issues/new?component=409828
Min
: Lint 8.0 and 8.1
Compiled
: Lint 8.7+
Artifact
: [androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html)
Since
: 2.5.0
Affects
: Resource files
Editing
: This check runs on the fly in the IDE editor
Implementation
: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/main/java/androidx/navigation/runtime/lint/DeepLinkInActivityDestinationDetector.kt)
Tests
: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/DeepLinkInActivityDestinationDetectorTest.kt)
Copyright Year
: 2022
Attaching a to an destination will never give
the right behavior when using an implicit deep link on
another app's task (where the system back should
immediately take the user back to the app that triggered
the deep link). Instead, attach the deep link directly to
the second activity (either by manually writing the appropriate
or by adding the to the start
destination of a nav host in that second activity).
(##) Example
Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/navigation/nav_main.xml:17:Warning: Do not attach a to an
destination. Attach the deeplink directly to the second
activity or the start destination of a nav host in the second activity
instead. [DeepLinkInActivityDestination]
<deepLink app:uri="www.example.com" />
--------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is the source file referenced above:
`res/navigation/nav_main.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_main"
app:startDestination="@id/fragment_main"
>
<fragment
android:id="@+id/fragment_main"
android:name="com.example.deeplink.MainFragment"
/>
<activity
android:id="@+id/activity_deep_link"
android:name="com.example.deeplink.DeepLinkActivity"
>
<deepLink app:uri="www.example.com" />
</activity>
</navigation>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can also visit the
[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-runtime-lint/src/test/java/androidx/navigation/runtime/lint/DeepLinkInActivityDestinationDetectorTest.kt)
for the unit tests for this check to see additional scenarios.
The above example was automatically extracted from the first unit test
found for this lint check, `DeepLinkInActivityDestinationDetector.expectFail`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=409828.
(##) Including
!!!
This is not a built-in check. To include it, add the below dependency
to your project.
```
// build.gradle.kts
implementation("androidx.navigation:navigation-runtime:2.9.0-rc01")
// build.gradle
implementation 'androidx.navigation:navigation-runtime:2.9.0-rc01'
// build.gradle.kts with version catalogs:
implementation(libs.navigation.runtime)
# libs.versions.toml
[versions]
navigation-runtime = "2.9.0-rc01"
[libraries]
# For clarity and text wrapping purposes the following declaration is
# shown split up across lines, but in TOML it needs to be on a single
# line (see https://github.com/toml-lang/toml/issues/516) so adjust
# when pasting into libs.versions.toml:
navigation-runtime = {
module = "androidx.navigation:navigation-runtime",
version.ref = "navigation-runtime"
}
```
2.9.0-rc01 is the version this documentation was generated from;
there may be newer versions available.
[Additional details about androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html).
(##) Suppressing
You can suppress false positives using one of the following mechanisms:
* Adding the suppression attribute
`tools:ignore="DeepLinkInActivityDestination"` on the problematic
XML element (or one of its enclosing elements). You may also need to
add the following namespace declaration on the root element in the
XML file if it's not already there:
`xmlns:tools="http://schemas.android.com/tools"`.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<deepLink xmlns:tools="http://schemas.android.com/tools"
tools:ignore="DeepLinkInActivityDestination" ...>
...
</deepLink>
```
* Using a special `lint.xml` file in the source tree which turns off
the check in that folder and any sub folder. A simple file might look
like this:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="DeepLinkInActivityDestination" severity="ignore" />
</lint>
```
Instead of `ignore` you can also change the severity here, for
example from `error` to `warning`. You can find additional
documentation on how to filter issues by path, regular expression and
so on
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).
* In Gradle projects, using the DSL syntax to configure lint. For
example, you can use something like
```gradle
lintOptions {
disable 'DeepLinkInActivityDestination'
}
```
In Android projects this should be nested inside an `android { }`
block.
* For manual invocations of `lint`, using the `--ignore` flag:
```
$ lint --ignore DeepLinkInActivityDestination ...`
```
* Last, but not least, using baselines, as discussed
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).