ReviewOS

craft-native/craft

fix(android): a recreated activity restores the wrong initial URL, and Recents re-fires the launch shortcut

#229
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Found while fixing #215. Both concern the intent that launched MainActivity.

A recreated activity restores the wrong initial URL

onNewIntent calls setIntent(intent). After a warm link, getIntent() is that link, not the one the app was launched with.

When the activity is recreated, onCreate runs again with a savedInstanceState and reads intent.data. That happens on a configuration change configChanges does not list (the manifest lists orientation|screenSize|screenLayout|keyboardHidden, so a locale or dark-mode change counts) and on process-death restore. #215 calls craftBridge.restoreInitialURL for this case, and on these paths getInitialURL() then answers with a link that did not launch the app. The same happened before #215 through handleIncomingDeepLink(intent, dispatch = false).

Suggested: save the launch URL in onSaveInstanceState and restore it from there, not from getIntent().

A relaunch from Recents probably fires the launch shortcut again

onCreate calls handleIncomingShortcut(intent) whenever savedInstanceState == null. An activity relaunched from Recents after its task finished carries the original intent, with FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY set. So the shortcut the app was first opened with is dispatched to the page again. #215 skips the launch link in that case; the shortcut path has no such check.

Sign in to comment on this issue.