This is what I found while investigating Facebook SDK.
If you have more than one app communicate each other, you can experience this.
There are defence codes in Facebook SDK, so it would not make a problem.
Set taskAffinity with a package name which holds the task.
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true"
android:taskAffinity="put your package name here">
<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="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
- Facebook Login Button Click
- FacebookActivity Create
- Attach LoginFragment to FacebookActivity
- Start LoginClient to login
- Get LoginMethodHandler
- Pass handlers with fail, until meet CustomTabLoginMethodHandler
- CustomTabLoginMethodHandler calls CustomTabMainActivity
- CustomTabMainActivity open CustomTab
- Facebook Login in CustomTab
- CustomTab redirect to CustomTabActivity
- CustomTabActivity calls CustomTabMainActivity to finish CustomTab
- CustomTabMainActivity was called on onNewIntent and sendBroadcast to CustomTabActivity and finish with loginresult
- Login Success
CustomTabMainActivity onCreate()
CustomTabActivity onCreate()
CustomTabMainActivity onNewIntent()
CustomTabMainActivity onNewIntent REDIRECT ACTION
CustomTabMainActivity sendResult()
CustomTabMainActivity onDestroy()
CustomTabActivity onDestroy()
CustomTabMainActivity onCreate()
CustomTabActivity onCreate()
Second CustomTabMainActivity onCreate()
Second CustomTabMainActivity REDIRECT ACTION
CustomTabActivity RESULT_CANCELED
CustomTabActivity redirectReceiver sendBroadcast()
CustomTabMainActivity redirectReceiver onReceived()
CustomTabMainActivity onNewIntent()
CustomTabMainActivity onNewIntent REFRESH ACTION
CustomTabMainActivity closeReceiver sendBroadcast()
CustomTabMainActivity sendResult()
CustomTabActivity closeReceiver onReceived()
CustomTabActivity onDestroy()
CustomTabMainActivity onDestroy()
Second CustomTabMainActivity onDestroy()
Run #5: ActivityRecord{ab3df4 u0 com.xxx.xxx.xxx/com.facebook.CustomTabMainActivity t332}
Run #4: ActivityRecord{b54c4d4 u0 com.xxx.xxx.xxx/com.facebook.CustomTabActivity t332}
Run #3: ActivityRecord{7df79ae u0 com.android.chrome/org.chromium.chrome.browser.customtabs.CustomTabActivity t331}
Run #2: ActivityRecord{4a5445f u0 com.xxx.xxx.xxx/com.facebook.CustomTabMainActivity t331}
Run #1: ActivityRecord{a27fb03 u0 com.xxx.xxx.xxx/com.facebook.FacebookActivity t331}
CustomTab libraries start activity with FLAG_ACTIVITY_NEW_TASK
https://chromium.googlesource.com/chromium/src/+/b8a4837ec4019de8ed1b1810663c6326c59ce33d/chrome/android/java_staging/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java#290
So what happened to me below.
- A app started activity of B app with startActivity() - in A app task
- B app started Facebook Activity - in A app task
- Facebook Activity started Chrome Custom Tab - in A app task
- Chrome Custom Tab started CustomTabActivity with New Task - in A app task
- Custom tab started CustomTabMainActivity - in B app task
- tasks are different so in CustomTabMainActivity onCreate was called.