tags: Android headaches android
Tencent’s TBS is used to load web pages in the Android project, and the X5 kernel has always been easy to use. It was found that some users’ phones occasionally crashed.
After researching, I found an error message:
Using WebView from more than one process at once with the same data directory is not supported.
Complete information:

The error that the user device is 9.0 or higher was originally because the behavior change of WebView was included in the behavior change of Android Pie.
To improve application stability and data integrity in Android 9, applications can no longer allow multiple processes to share the same WebView data directory.
Such data directories generally store cookies, HTTP caches, and other persistent and temporary storage related to web browsing.
In most cases, your app should only use the classes in the android.webkit package, such as WebView and CookieManager, in one process.
For example, you should move all Activity objects that use WebView into the same process.
You can enforce the "only one process" rule more strictly by calling disableWebView() in other processes of the application.
This call can prevent WebView from being incorrectly initialized in these other processes, even if it is a call from a dependent content library.
If your application must use instances of WebView in multiple processes, you must first use the WebView.setDataDirectorySuffix() function to specify a unique data directory suffix for each process, and then use a given instance of WebView in that process.
This function will put the network data of each process into its own directory in the application data directory.
Solution:
public class WebApplication extends Application {
private static final String PROCESS = "com.sunzn.core";
@Override
public void onCreate() {
super.onCreate();
initPieWebView();
}
private void initPieWebView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName(this);
if (!PROCESS.equals(processName)) {
WebView.setDataDirectorySuffix(getString(processName, "sunzn"));
}
}
}
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;
}
public String getString(String s, String defValue) {
return isEmpty(s) ? defValue : s;
}
public boolean isEmpty(String s) {
return s == null || s.trim().length() == 0;
}
}
After introducing the two JAR packages of Ali SMS: The reason is that Modulepath is selected when adding the Jar package. can be resolved after changing to Classpath....
android adb: error: more than one device / emulator solution First, the computer sometimes adb usb connected to multiple devices at this time if the adb prompt actionerror: more than one device...
Use environment: One computer (Win10), a simulator (Mumu) Error process Run in CMD Appearance error Find reason There are two devices, weird, I only have a simulator. . . Equipment survey Specify conn...
Yes, in WPF the GroupBox will contain maximum of 1 element. You can include Grid as its child and in grid specify your desired components. For example 1 placed two buttons in GroupBox using Grid....
Problem: The program crashes when calling pushViewController The application has such a function, click on the push notification to jump to the corresponding message interface, But this interface is c...
bug: Pushing the same view controller instance more than once is not supported This bug is due to useNavigation ControllerWhen an interface has not been released, it is pushed again. After checking St...
Topic The employees of the bus buckle use the employee card to open the door. Whenever an employee uses his employee card, the security system will record the name and time of use of the employee. If ...
Foreword Recently implemented a webview loading article, then you can display the comments and the interfaces for comments. When you enter this interface, come to a load movie, when WebView is loaded,...
Python delete one or more same elements in list at once Delete a single element in the list at once Delete multiple identical elements in the list at once Delete a single element in the list at once P...
javax.servlet is accessible from more than one module The javax.servlet.XXX error in the java project is as follows: Generally speaking, there are two situations: either more servlet-api.jar is introd...