Skip to content

Conversation

f0wu5u
Copy link

@f0wu5u f0wu5u commented Sep 18, 2024

In reaction to this issue #558 and this closed PR #559.

This adds the;

import android.content.intent

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    setIntent(intent)
  }

by default if import android.content.intent is not already in MainActivity and if override fun onNewIntent(intent: Intent?) is not already implemented.

This ultimately resolves issue with expo android not opening deeplinks when app is in background

cc: @iway1

@f0wu5u f0wu5u force-pushed the patch/expo-android-on-new-intent-override branch from 2ada035 to 1a3ba77 Compare September 18, 2024 14:50
@erenkulaksiz
Copy link

why not merge?🚨🚨🚨🚨🚨🚨

@jp1987
Copy link

jp1987 commented Jan 27, 2025

Please merge this.

Co-authored-by: Jesper Paardekooper <[email protected]>

if (!nextContent.includes(intentImportString)){
const packageString = `${packageName}\n`
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at the end of the import.

Suggested change
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`)
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}\n`)

@saseungmin
Copy link
Contributor

saseungmin commented Jun 10, 2025

I encountered the following error:

Task :app:compileDebugKotlin FAILED
e: file:///Users/saseungmin/workspace/essentory-app/android/app/src/main/java/com/essentory/app/MainActivity.kt:17:3 'onNewIntent' overrides nothing.
e: file:///Users/saseungmin/workspace/essentory-app/android/app/src/main/java/com/essentory/app/MainActivity.kt:18:23 Argument type mismatch: actual type is 'android.content.Intent?', but 'android.content.Intent' was expected.

Fixed by updating the code to:

import android.content.Intent

override fun onNewIntent(intent: Intent) {
  super.onNewIntent(intent)
  setIntent(intent)
}
  • Expo SDK 53, react-native v0.79.2 project

@thalmann-christof
Copy link

We have also encountered the issue like @saseungmin, and the suggested fix solved this issue 👍 Running on Expo 52, react-native 0.76.9.

Changed both appearances of (intent: Intent?) to (intent: Intent).

This resolves the expo issue with Android not opening deeplinks when the app is in the background!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants