How To Avoid Handling A Deep Link Twice On Android?
I have an android test app that handles a custom URL deep link (e.g. myapp://xxx/yyy) inside onResume as follows: if (intent.getAction() != Intent.ACTION_VIEW) return; String data
Solution 1:
Based on the comments above, the solution that works best seems to be:
- place the URL processing code inside onCreate(state)
- only process the URL if state == null
Code sample:
voidonCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) {
if (intent.getAction() == Intent.ACTION_VIEW) {
String data = intent.getDataString();
if (data != null) {
// ... process URL in 'data'
}
}
}
}
Solution 2:
Solution 3:
I think you should process the url in OnNewIntent and onCreate(neither will be call when become active from background), to avoid multiple processing when rotating, there are two solutions to me:
Solution 1:
In onCreate, ignore it if savedInstanceState is no null, This solution based on multiple calling is from rotation, and only need changes on app side.
Solution 2:
Make the deeplink url dynamic, which changes every time(like myapp://xxx/yyy?stamp=xxxx), and you can check if the url is already processed. This solution can take any case, but need you modify the url ( maybe from server side ).
Post a Comment for "How To Avoid Handling A Deep Link Twice On Android?"