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

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;
    }

你可能感兴趣的:(Android,问题解决方案)