Android Pie (9.0) WebView in multi-process

后端 未结 3 1819
既然无缘
既然无缘 2020-12-24 02:31

Starting Android Pie (API 28), Google isn\'t allowing using a single WebView instance in 2 different processes.

Documentation: https://developer.android.com/referenc

3条回答
  •  佛祖请我去吃肉
    2020-12-24 03:14

    To summarize the fix with all the improvements, this is the code in Kotlin:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        if (packageName != Application.getProcessName()) {
            WebView.setDataDirectorySuffix(Application.getProcessName())
        }
    }
    

    Add it to your Application class to onCreate() method.

    Note this is will only fix problem with maximum 2 processes. If your app is using more, you have to provide different WebView suffix for each of them.

提交回复
热议问题