When I try to send intent to activity was being displayed using app link, new activity is created

98 Views Asked by At

My app implements OAuth 2.0 using a custom tab and App Link, and obtains data sent with a redirect URL through App Link through onNewIntent().
I'm trying to send a method to send this data to the ViewModel of the Activity along with some data that is sent when displaying this Activity to the server side along with some data stored using SavedStateHandle.
According to my Firebase Crashlytics and customer reports, depending on device, onNewIntent() isn't called, but onCreate(), where a new activity is created, is called.
However, at this time, the data stored in SavedStateHandle doesn't exist, and since it was not created with putExtra(), there is no data and a NullPointException occurs. I think this is an impossible case based on my knowledge because there are additional settings as shown below, but can I know why a new Activity is created like this?

  1. The launch mode uses singleTask.
  2. When displaying an activity, the flag is not set separately.
  3. Multi module is used and compose is not used.
  4. We added processing to disable the do not preserve activity mode, so if that happens, the activity will not be reached.
  5. It is used Kotlin, and the Activity lib version is 1.4.0 and the Lifecycle version is 2.4.1.
  6. This occurs regardless of OS version and device brand.
1

There are 1 best solutions below

0
PJH On

Thanks to the comments, I solved it like this.

  1. Separate the activity that runs the chrome custom tab and the activity for App Link.
  2. Add the following flag to the intent of the custom tab.
.intent.apply {
    flags = Intent.FLAG_ACTIVITY_NO_HISTORY
    addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
  1. Set the launch mode of the App Link activity to singleTop.
  2. Before running the chrome custom tab in the activity that runs the chrome custom tab, save the data needed by the activity for App Link as SharedPrefrences.
  3. After retrieving data from SharedPreferences in the App Link activity, reset the data in SharedPreferences. (For reference, I used EncryptedSharedPreferences.)