diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 8e2ae44994..59135c2708 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix +import android.app.Activity import android.content.Context import android.content.Intent import android.os.Build @@ -11,6 +12,7 @@ import android.os.Bundle import android.preference.PreferenceManager import android.util.AttributeSet import android.view.View +import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.navigation.fragment.NavHostFragment @@ -105,6 +107,8 @@ open class HomeActivity : AppCompatActivity() { navHost.navController.popBackStack(R.id.browserFragment, true) allSessionsRemoved = false } + + showSoftwareKeyboardIfNecessary() } override fun onDestroy() { @@ -140,6 +144,27 @@ open class HomeActivity : AppCompatActivity() { super.onBackPressed() } + override fun onPause() { + super.onPause() + hideSoftwareKeyboardIfNecessary() + } + + private fun showSoftwareKeyboardIfNecessary() { + (getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply { + currentFocus?.also { + this.showSoftInput(it, 0) + } + } + } + + private fun hideSoftwareKeyboardIfNecessary() { + (getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply { + currentFocus?.also { + this.hideSoftInputFromWindow(it.windowToken, 0) + } + } + } + private fun handleCrashIfNecessary(intent: Intent?) { if (intent == null) { return } if (!Crash.isCrashIntent(intent)) { return }