diff --git a/app/src/main/java/org/mozilla/focus/activity/MainActivity.kt b/app/src/main/java/org/mozilla/focus/activity/MainActivity.kt index 31450bf0b0a..aaff1126e86 100644 --- a/app/src/main/java/org/mozilla/focus/activity/MainActivity.kt +++ b/app/src/main/java/org/mozilla/focus/activity/MainActivity.kt @@ -58,6 +58,9 @@ open class MainActivity : LocaleAwareAppCompatActivity() { updateSecureWindowFlags() super.onCreate(savedInstanceState) + // Checks if Activity is currently in PiP mode if launched from external intents, then exits it + checkAndExitPiP() + if (!isTaskRoot) { if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN == intent.action) { finish() @@ -112,6 +115,14 @@ open class MainActivity : LocaleAwareAppCompatActivity() { AppReviewUtils.showAppReview(this) } + private fun checkAndExitPiP() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode && intent != null) { + // Exit PiP mode + moveTaskToBack(false) + startActivity(Intent(this, this::class.java).setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) + } + } + final override fun onUserLeaveHint() { val browserFragment = supportFragmentManager.findFragmentByTag(BrowserFragment.FRAGMENT_TAG) as BrowserFragment?