0

I've bumped into a strange issue - WebView becomes unresponsive when I finish the activity that started the activity with the WebView BUT it doesn't happen on the first launch, only on the consecutive ones and it also happens on Android 6 and 7, newer Android versions seem to handle that gently. The full project which reproduces this can be found here

I have two activities Launcher

class LauncherActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        startActivity(Intent(this, MainActivity::class.java))
        finish()
    }
}

And MainActivity with the WebView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val webView = findViewById<WebView>(R.id.oauthWebView)
        webView.loadUrl("https://semantic-ui.com/examples/login.html")
    }
}

When I start the app the first time everything seems okay, but the second time when I open it, WebView becomes unresponsive, the keyboard is not showing and it happens right after Launcher onDestroy If I'm not calling finish in the LauncherActivity everything is fine. It looks like finishing LauncherActivity has some impact on WebView loading or some other process that's happening under the hood. It's pretty weird, Logcat is not very helpful either. Maybe any of you can provide some hint what might be the reason for such behaviour?

Side note: I'm not looking for answers on how to architect my navigation better, I know it can be done differently - I'm curious why WebView is behaving so weird.

Jogosb
  • 155
  • 1
  • 12

1 Answers1

0

Can you try this?

 val webView = findViewById<WebView>(R.id.oauthWebView)
 webView.getSettings().setJavaScriptEnabled(true);      
 webView.loadUrl("https://semantic-ui.com/examples/login.html")
  
Asad khan
  • 156
  • 7
  • It doesn't help. I've tested quite a lot webview configs and I'm pretty confident it's not related to that but thanks! – Jogosb Sep 27 '20 at 18:39
  • Tested your code, it is working as expected. I am unable to recreate this issue. – Asad khan Sep 27 '20 at 18:44
  • Scenario is: 1. Open the app - edit text of the form is opening the keyboard/is responisve basicall 2. Press back 3. Open the app again 4. After few seconds edit text is not responsive -> It has to be physical device with android 6 or 7. – Jogosb Sep 27 '20 at 18:45
  • Can you try to remove the launcher activity and make your MainActivity as a launcher activity and test the output? – Asad khan Sep 27 '20 at 18:46
  • I can and I will work - the issue is why this launcher causes this strange unresponsiveness – Jogosb Sep 27 '20 at 18:48
  • Also can you try adding android:hardwareAccelerated="true" to your Manifest file under application tag? – Asad khan Sep 27 '20 at 18:52