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;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章