diff --git a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt index 66406e36e9830cf6827ca1caf639003910423d8a..cd83ad58d2c2e5be5eac0238dea89cd21f44d008 100644 --- a/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt +++ b/app/src/main/java/at/bitfire/davdroid/MailAccountSyncHelper.kt @@ -27,7 +27,11 @@ object MailAccountSyncHelper { private const val MAIL_RECEIVER_CLASS = "com.fsck.k9.account.AccountSyncReceiver" private const val ACTION_PREFIX = "foundation.e.accountmanager.account." - fun onAccountLoggedIn(applicationContext : Context?) { + fun onAccountLoggedIn(applicationContext: Context?, packageToBeOpened: String?) { + if (isOpeningMailAppActivity(packageToBeOpened)) { + return + } + val intent = getIntent() intent.action = ACTION_PREFIX + "create" applicationContext?.sendBroadcast(intent) @@ -51,4 +55,14 @@ object MailAccountSyncHelper { intent.component = ComponentName(MAIL_PACKAGE, MAIL_RECEIVER_CLASS) return intent } + + // if mail app's activity is needed to open after the auth, no need to send broadCast. + // because, sending broadcast will fail. The cause is, mail app will be opened in a new task + private fun isOpeningMailAppActivity(packageToBeOpened: String?): Boolean { + if (packageToBeOpened == null || packageToBeOpened != MAIL_PACKAGE) { + return false + } + + return true + } } \ No newline at end of file diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt index f76d27a609704f19cd58efc168fd088188f2eb4d..26a940f4960ab6888ca4302494f4ee25c4336afb 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.kt @@ -188,7 +188,7 @@ class AccountDetailsFragment : Fragment() { val packageToBeOpened = requireActivity().intent.getStringExtra(LoginActivity.OPEN_APP_PACKAGE_AFTER_AUTH) val activityToBeOpened = requireActivity().intent.getStringExtra(LoginActivity.OPEN_APP_ACTIVITY_AFTER_AUTH) openApp(packageToBeOpened, activityToBeOpened) - MailAccountSyncHelper.onAccountLoggedIn(context?.applicationContext) + MailAccountSyncHelper.onAccountLoggedIn(context?.applicationContext, packageToBeOpened) } private fun openApp(packageToBeOpened: String?, activityToBeOpened: String?) {