Deep linking not working when app is in background state React native












1














i am creating e-commerce app based react native.here i need open single product page from url shared.actually it will work when app is in killed state, but incase of app is in background/inactive state it won't work. the sharing url gets null when opening on background/inactive state.I have attached my code.



// following code working for app killing state

componentWillMount() {

if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}

}

Not working code following..



componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}

this.state.appState declared in constructor(props)

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!');debugger
if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}
}
}


when i open external link from whatsapp and app in background state Linking.getInitialURL() received as null ..



Following i have in manifest file



<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="demo1.zgroo.com" />
</intent-filter>
</activity>


following is my sample URL..



http://demo1.zgroo.com/xxxx



Kindly let me know any solutions..



thanks in advance..










share|improve this question
























  • Have you added deeplink code in manifest?
    – Athira
    Nov 12 '18 at 5:24










  • with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
    – abdul sathar
    Nov 12 '18 at 5:39












  • Added manifest code can pls check now?
    – abdul sathar
    Nov 12 '18 at 5:45
















1














i am creating e-commerce app based react native.here i need open single product page from url shared.actually it will work when app is in killed state, but incase of app is in background/inactive state it won't work. the sharing url gets null when opening on background/inactive state.I have attached my code.



// following code working for app killing state

componentWillMount() {

if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}

}

Not working code following..



componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}

this.state.appState declared in constructor(props)

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!');debugger
if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}
}
}


when i open external link from whatsapp and app in background state Linking.getInitialURL() received as null ..



Following i have in manifest file



<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="demo1.zgroo.com" />
</intent-filter>
</activity>


following is my sample URL..



http://demo1.zgroo.com/xxxx



Kindly let me know any solutions..



thanks in advance..










share|improve this question
























  • Have you added deeplink code in manifest?
    – Athira
    Nov 12 '18 at 5:24










  • with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
    – abdul sathar
    Nov 12 '18 at 5:39












  • Added manifest code can pls check now?
    – abdul sathar
    Nov 12 '18 at 5:45














1












1








1







i am creating e-commerce app based react native.here i need open single product page from url shared.actually it will work when app is in killed state, but incase of app is in background/inactive state it won't work. the sharing url gets null when opening on background/inactive state.I have attached my code.



// following code working for app killing state

componentWillMount() {

if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}

}

Not working code following..



componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}

this.state.appState declared in constructor(props)

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!');debugger
if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}
}
}


when i open external link from whatsapp and app in background state Linking.getInitialURL() received as null ..



Following i have in manifest file



<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="demo1.zgroo.com" />
</intent-filter>
</activity>


following is my sample URL..



http://demo1.zgroo.com/xxxx



Kindly let me know any solutions..



thanks in advance..










share|improve this question















i am creating e-commerce app based react native.here i need open single product page from url shared.actually it will work when app is in killed state, but incase of app is in background/inactive state it won't work. the sharing url gets null when opening on background/inactive state.I have attached my code.



// following code working for app killing state

componentWillMount() {

if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}

}

Not working code following..



componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}

this.state.appState declared in constructor(props)

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!');debugger
if (Platform.OS === 'android') {
console.log("Testing");debugger

//Constants.OneTimeFlag == false;
Linking.getInitialURL().then(url => {
console.log(url);
var str = url
var name = str.split('/')[4]
Constants.isLinking = true;
this.setState({ shop_Id: name})


if (str)
{
this.setState({ isFromHomeLinking:'FROM_LINK' })
this.props.navigation.navigate('SingleProductScreen', { ListViewClickItemHolder: [this.state.shop_Id,1,this.state.isFromHomeLinking] });

}


});

}

else {
Linking.addEventListener('url', this.handleNavigation);
}
}
}


when i open external link from whatsapp and app in background state Linking.getInitialURL() received as null ..



Following i have in manifest file



<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="demo1.zgroo.com" />
</intent-filter>
</activity>


following is my sample URL..



http://demo1.zgroo.com/xxxx



Kindly let me know any solutions..



thanks in advance..







android react-native deep-linking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 10:44









Mike Kinghan

30.1k763112




30.1k763112










asked Nov 12 '18 at 5:10









abdul sathar

1,57411529




1,57411529












  • Have you added deeplink code in manifest?
    – Athira
    Nov 12 '18 at 5:24










  • with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
    – abdul sathar
    Nov 12 '18 at 5:39












  • Added manifest code can pls check now?
    – abdul sathar
    Nov 12 '18 at 5:45


















  • Have you added deeplink code in manifest?
    – Athira
    Nov 12 '18 at 5:24










  • with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
    – abdul sathar
    Nov 12 '18 at 5:39












  • Added manifest code can pls check now?
    – abdul sathar
    Nov 12 '18 at 5:45
















Have you added deeplink code in manifest?
– Athira
Nov 12 '18 at 5:24




Have you added deeplink code in manifest?
– Athira
Nov 12 '18 at 5:24












with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
– abdul sathar
Nov 12 '18 at 5:39






with out deeplink code in manifest .. app closing state not works right..let me edit manifest code also wait
– abdul sathar
Nov 12 '18 at 5:39














Added manifest code can pls check now?
– abdul sathar
Nov 12 '18 at 5:45




Added manifest code can pls check now?
– abdul sathar
Nov 12 '18 at 5:45












1 Answer
1






active

oldest

votes


















2














You need to register Linking listener for this case.



componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}


For more https://facebook.github.io/react-native/docs/linking






share|improve this answer





















  • thanks for answer
    – abdul sathar
    Nov 12 '18 at 12:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256246%2fdeep-linking-not-working-when-app-is-in-background-state-react-native%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You need to register Linking listener for this case.



componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}


For more https://facebook.github.io/react-native/docs/linking






share|improve this answer





















  • thanks for answer
    – abdul sathar
    Nov 12 '18 at 12:31
















2














You need to register Linking listener for this case.



componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}


For more https://facebook.github.io/react-native/docs/linking






share|improve this answer





















  • thanks for answer
    – abdul sathar
    Nov 12 '18 at 12:31














2












2








2






You need to register Linking listener for this case.



componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}


For more https://facebook.github.io/react-native/docs/linking






share|improve this answer












You need to register Linking listener for this case.



componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}


For more https://facebook.github.io/react-native/docs/linking







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 12:05









Anurag Chutani

1366




1366












  • thanks for answer
    – abdul sathar
    Nov 12 '18 at 12:31


















  • thanks for answer
    – abdul sathar
    Nov 12 '18 at 12:31
















thanks for answer
– abdul sathar
Nov 12 '18 at 12:31




thanks for answer
– abdul sathar
Nov 12 '18 at 12:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256246%2fdeep-linking-not-working-when-app-is-in-background-state-react-native%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ