react-native
react-native copied to clipboard
Linking.addEventListener("url",event =>{}) called multiple times on Android.
Description
Linking.addEventListener("url",event =>{}) called multiple times on Android.On iOS, this listener is normal. But on Android,it is wired, and i print its listener count is 2.
Linking.listenerCount("url")
Even though i killed app ,then i open app again, this listener stilled called twice or more. My code is as follows,
componentDidMount() {
this.listener = Linking.addEventListener('url', event => {
const url = event.url;
console.log("===== Linking addEventListener====url: " + url)
if (Tools.isNotEmptyStr(url)) {
const urlObj = Tools.queryString(url);
this.goToOtherPage(urlObj)
}
})
}
I tried to add these code to relove, but it can not help.
1、Linking.removeAllListeners("url")
2、this.listener && this.listener.remove()
React Native Version
0.71.13
Output of npx react-native info
info Fetching system and libraries information... System: OS: macOS 13.4.1 CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz Memory: 200.26 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 17.0.1 - /usr/local/bin/node Yarn: Not Found npm: 8.1.0 - /usr/local/bin/npm Watchman: 2021.11.08.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: API Levels: 23, 26, 27, 28, 29, 30, 31, 32, 33 Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0 System Images: android-30 | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10671973 Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild Languages: Java: 17.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.13 => 0.71.13 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
1、Open then app, then open a certain URL in the browser and click the button on the webpage to jump to a specific page in the app. Maybe it is normal at the first time. 2、Kill the app, then reopen app again. 3、Reopen a certain URL in the browser and click the button on the webpage to jump to a specific page in the app, you will find "Linking.addEventListener" called multiple times.
Snack, screenshot, or link to a repository
The relevant information I printed out:
LOG ===== Linking addEventListener====url:myAppscheme://?pageName=GoodDetail&id=2 , listenerCount=2
LOG ===== Linking addEventListener====url: myAppscheme://?pageName=GoodDetail&id=2 , listenerCount=2
LOG ==goToOtherPage== {"id": "2", "pageName": "GoodDetail"}
....
LOG ==goToOtherPage== {"id": "2", "pageName": "GoodDetail"}
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.