当前位置:   article > 正文

Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the...

using webview from more than one process at once with the same data director

1、异常日志:Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377

2、异常出现情景:因为Android P行为变更,不可多进程使用同一个目录webView,需要为不同进程webView设置不同目录
3、解决方式:重写项目Application,然后为其它进程webView设置目录
代码如下:

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
      String processName = getProcessName(this);
      if (!"com.yc.kabuqinuo".equals(processName)){//判断不等于默认进程名称
          WebView.setDataDirectorySuffix(processName);}
  }

    public  String getProcessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/375316
推荐阅读
  

闽ICP备14008679号