A web page refreshing method and device based on WebView
By setting multiple scheduling timers in WebView and monitoring their status, the scheduler is automatically switched to adapt to the terminal's power limitations, which solves the problem of low animation and game smoothness in WebView in power-saving mode and improves the user experience.
Patent Information
- Application Number
- CN202310600909.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-25
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-05-25
AI Technical Summary
In power-saving or low-power modes on mobile devices, the timer scheduling frame rate of WebView is limited, resulting in poor web page animations and motion effects, slow game speed, and a reduced user experience.
By setting a first scheduling timer and a second scheduling timer, the working status of WebView and the terminal status are monitored, and the scheduling timer is automatically switched to maintain the refresh frequency required by the business. The second scheduling timer is used to replace the first scheduling timer for task scheduling.
In power saving mode or low power mode, web page animations and games remain smooth, improving the user experience while avoiding unnecessary power consumption.
Smart Images

Figure HDA0004249084900000011 
Figure HDA0004249084900000012 
Figure HDA0004249084900000021
Abstract
Description
Technical Field
[0001] This application relates to the field of mobile terminal Internet, and in particular to a webpage refresh method and apparatus based on WebView. Background Technology
[0002] When developing time-linear functions such as animations, games, and motion effects for mobile web pages, the JavaScript time scheduling API provided by WebView is relied upon. For applications requiring strong real-time performance, such as games, animations, and motion effects, web page refreshes are typically performed in a more real-time and precise manner. However, when the mobile terminal system is in power-saving or low-power mode, WebView limits the frame rate of the timer, preventing the mobile web page from refreshing the screen and completing the upper-layer rendering tasks as required by the business logic. Consequently, when the phone enters power-saving or low-power mode and other frequency-limited scenarios, page animations and motion effects are poor, game speed is slow, page smoothness is reduced, and the user experience is poor. Summary of the Invention
[0003] In view of this, this application provides a webpage refresh method and apparatus based on WebView to improve the user experience of webpage refresh based on WebView when WebView is in a frequency-limited state.
[0004] The first aspect of this invention provides a webpage refresh method based on WebView, comprising:
[0005] Set a first scheduling timer and a second scheduling timer; wherein, the first scheduling timer is the default scheduling timer of WebView, and the second scheduling timer is a scheduling timer with a refresh cycle determined based on business needs;
[0006] Monitor the working status of WebView and the status of the mobile terminal where WebView is located;
[0007] If the WebView is in frequency-limiting mode, the second scheduling timer is used instead of the first scheduling timer as the WebView's task scheduler to refresh the WebView-based webpage; otherwise, the first scheduling timer is used as the WebView's task scheduler to refresh the WebView-based webpage.
[0008] The frequency limiting mode is determined by monitoring the execution time and interval of the WebView's tasks, as well as the status of the mobile terminal where the WebView is located.
[0009] In some embodiments, the frequency limiting mode is determined by monitoring the execution time of WebView tasks and the task interval, including the following method:
[0010] Get the execution time T1 of the current task and the current scheduling interval T2 between the current task and the preceding adjacent task.
[0011] The current task scheduling frame rate f is determined based on the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task; wherein, the current task scheduling frame rate f is inversely proportional to the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task.
[0012] If the execution time T1 of the current task is less than the first threshold and the duration exceeds the third threshold, and the current task scheduling frame rate f is less than the second threshold and the duration exceeds the third threshold, then it is determined that WebView is in frequency limiting mode.
[0013] In some embodiments, the method for determining the frequency limiting mode by monitoring the state of the mobile terminal where the WebView is located includes:
[0014] By monitoring the status of the mobile terminal where the WebView is located through the operating system API, if the time the mobile terminal where the WebView is located is in power saving mode or low power mode exceeds the fourth threshold, it is determined that the mobile terminal where the WebView is located is in frequency limiting mode.
[0015] In some embodiments, before using the second scheduling timer to replace the first scheduling timer as the WebView task scheduler to refresh the WebView-based webpage, the service with the highest required refresh frequency among all services involved in the current WebView-based webpage is identified, and the lowest refresh frequency requirement of the service with the highest required refresh frequency is used as the predetermined frame rate of the second scheduling timer.
[0016] In some embodiments, the method of replacing the first scheduling timer with the second scheduling timer includes:
[0017] Register a global task function name for a timer based on JavaScript;
[0018] The second scheduling timer is started by communicating with Native via JavaScript based on the global task function name of the timer.
[0019] In some embodiments, the method of replacing the first scheduling timer with the second scheduling timer as the task scheduler of WebView to refresh the WebView-based webpage includes:
[0020] The second scheduling timer is started according to the predetermined frame rate, and the native task is scheduled according to the predetermined frame rate through CADisplayLink.
[0021] During each Native scheduling, JavaScript is scheduled according to a predetermined frame rate through Native-to-JavaScript communication, causing the webpage to refresh.
[0022] In some embodiments, when the second scheduling timer is used to replace the first scheduling timer as the task scheduler of WebView to refresh the webpage based on WebView, the frequency of WebView calling empty functions is monitored.
[0023] If the frequency of WebView calling empty functions exceeds the fifth threshold, the first scheduling timer will be used as the task scheduler of WebView to refresh the webpage based on WebView when executing the next task.
[0024] In some embodiments, when the second scheduling timer is used to replace the first scheduling timer as the task scheduler of WebView to refresh the webpage based on WebView, the status of the mobile terminal where WebView is located is monitored.
[0025] If the mobile terminal where the WebView is located exits power saving mode or low power mode, the first scheduling timer is used as the task scheduler of the WebView to refresh the webpage based on the WebView when executing the next task.
[0026] The second invention provides a webpage refresh device based on WebView, comprising:
[0027] The scheduling timer includes a first scheduling timer and a second scheduling timer; wherein the first scheduling timer is the default scheduling timer of WebView, and the second scheduling timer is a scheduling timer with a refresh cycle determined based on business needs;
[0028] A monitoring unit, configured to monitor the working status of the WebView and the status of the mobile terminal where the WebView is located;
[0029] The judgment and selection unit is configured to perform the following actions: if the working state of WebView is in frequency limiting mode, then the second scheduling timer is used to replace the first scheduling timer as the task scheduler of WebView to refresh the web page based on WebView; otherwise, the first scheduling timer is used as the task scheduler of WebView to refresh the web page based on WebView.
[0030] The frequency limiting mode is determined by monitoring the execution time and interval of the WebView's tasks, as well as the status of the mobile terminal where the WebView is located.
[0031] A third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the steps of the WebView-based webpage refresh method described in any of the preceding claims.
[0032] This invention monitors and identifies whether a WebView enters a frequency-limiting mode, and modifies the scheduling timer to ensure that the WebView in frequency-limiting mode maintains the refresh rate required by the webpage's business logic. This solves the technical problems of poor page animation and low game smoothness in mobile terminal WebView under frequency-limiting conditions, and improves user experience while avoiding unnecessary power consumption. Attached Figure Description
[0033] Figure 1 This is a flowchart illustrating an exemplary embodiment of a WebView-based webpage refresh method.
[0034] Figure 2 A flowchart illustrating the working status of a WebView, as shown in an exemplary embodiment;
[0035] Figure 3 A flowchart illustrating, as an exemplary embodiment, a method for refreshing a WebView-based webpage using different scheduling timers based on the working state of the WebView;
[0036] Figure 4 A flowchart illustrating a method for refreshing a webpage when a WebView exits the frequency-limiting mode, as shown in an exemplary embodiment;
[0037] Figure 5 This is a schematic block diagram of a WebView-based webpage refresh device in an exemplary embodiment. Detailed Implementation
[0038] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0039] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0040] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0041] When developing web-based animations, games, and motion effects on mobile devices running operating systems such as Android and iOS, especially for real-time applications, `requestAnimationFrame` is typically used as the time scheduling API. For example, this API triggers scheduled tasks at 60fps (1 / 60th of a second, or 16.67 milliseconds) to meet various web-based business requirements. However, when the system is in power-saving or low-power mode, WebView limits the frame rate of the timer API. For instance, on iOS, the frame rate might drop from 60fps to 30fps. This prevents mobile web pages from scheduling tasks precisely at the screen refresh rate of 60fps to complete upper-layer rendering. The resulting user experience is that when the phone enters power-saving or low-power mode, the animation, motion effects, and game speeds slow down, reducing the smoothness of the page experience.
[0042] One way to solve the above problems is to indirectly bypass the low-battery frequency limit by utilizing browser features. For example, when elements in a webpage's functionality are in 3D hardware-accelerated animation or inertial scrolling, the WebView temporarily disables the frequency limit, allowing these elements to load smoothly. This method can temporarily circumvent the WebView frequency limit by continuously manipulating hidden elements for 3D animation hardware acceleration during time-based tasks like requestAnimationFrame. However, frequent manipulation of webpage elements for 3D animation acceleration consumes normal WebView rendering resources, affecting page rendering performance and causing page rendering blockage. Furthermore, the intervals between each hardware acceleration operation of hidden elements can easily cause page stuttering, making this method unsuitable for long-running pages like games or scenarios with high real-time requirements.
[0043] In view of this, the present invention provides a webpage refresh method based on WebView, which adaptively determines whether the webpage on the mobile terminal has entered the frequency limit state, and automatically switches to a timer scheduler designed based on business needs to perform screen frame rate scheduling, ensuring that JavaScript can perform task scheduling according to an approximate screen frame rate, so that the upper-layer business is unaware of it, and the animation and game smoothness are not affected by power saving mode or low power mode.
[0044] Figure 1 This is a flowchart of a webpage refresh method based on WebView, as an exemplary embodiment of the present invention.
[0045] Please refer to Figure 1 A WebView-based webpage refresh method includes:
[0046] S101. Set a first scheduling timer and a second scheduling timer; wherein, the first scheduling timer is the default scheduling timer of WebView, and the second scheduling timer is a scheduling timer with a refresh cycle determined based on business needs.
[0047] The first scheduled timer can be obtained by WebView using the scheduled timer in the default requestAnimationFrame.
[0048] The second scheduling timer is a refresh period determined based on business needs, and is customized through the iOS or Android client timer. The second scheduling timer is not fixed to a specific frame rate; its frame rate can be determined to be 60fps, 90fps, 120fps, etc., according to different business requirements.
[0049] In some embodiments, a new requestAnimationFrame based on a second scheduling timer can be created through rewriting. The business logic of the WebView-based webpage calls the global requestAnimationFrame to start the timer task in the original manner.
[0050] S102. Monitor the working status of WebView and the status of the mobile terminal where WebView is located.
[0051] You can monitor the WebView by registering a global frequency-limiting event listener function, such as, but not limited to, global_onFrequencyChanged.
[0052] The global frequency-limiting event listener function should at least monitor the execution time and interval of tasks performed by the WebView, as well as the state of the mobile terminal where the WebView resides. Each time JavaScript calls `requestAnimationFrame`, it should monitor the WebView's state, determine if it is in frequency-limiting mode, and based on the result, guide whether to use the default `requestAnimationFrame`'s timer as the first timer or a second timer with a refresh cycle determined by business needs as the timer for refreshing the WebView's webpage.
[0053] The frequency limiting mode is determined by monitoring the execution time and interval of tasks performed by the WebView, as well as the status of the mobile terminal where the WebView is located.
[0054] The following is a feasible embodiment that specifically explains the monitoring process of the global frequency-limiting event listener function on the execution time and interval of WebView tasks, such as... Figure 2 As shown.
[0055] Please refer to Figure 2 Methods for monitoring the working status of WebView include:
[0056] S201, Get the execution time T1 of the current task, and the current scheduling interval T2 between the current task and the preceding adjacent task.
[0057] Taking the call to `requestAnimationFrame` as an example, the execution time T1 of each `requestAnimationFrame` task is collected, as well as the current scheduling interval T2 between the current task and the preceding adjacent task. Collection of the continuous frame count for these variables is initiated at appropriate times. The units for task execution time T1 and the current scheduling interval T2 between the current task and the preceding adjacent task are both seconds. Each independent task in the business logic is used as the standard for judging the working state of the WebView. The execution time T1 of `requestAnimationFrame` and the current scheduling interval T2 between the current task and the preceding adjacent task are collected for each independent task.
[0058] S202. Determine the current task scheduling frame rate f based on the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task. The current task scheduling frame rate f is inversely proportional to the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task.
[0059] That is, f = 1 / T²,
[0060] Where f is the current task scheduling frame rate, and T2 is the current scheduling interval between executing the current task and the preceding adjacent task.
[0061] S203. If the execution time T1 of the current task is less than the first threshold, the current task scheduling frame rate f is less than the second threshold, and the duration exceeds the third threshold, then it is determined that WebView is in frequency limiting mode.
[0062] Continuing with the example of calling `requestAnimationFrame`, if the execution time T1 of the current task is found to be less than a first threshold, a frame count timer is started to obtain the first continuous frame count F1 in which the execution time T1 of the current task is continuously less than the first threshold. Similarly, if the current task scheduling frame rate f is found to be less than a second threshold, a frame count timer is started to obtain the second continuous frame count F2 in which the current task scheduling frame rate f is continuously less than the second threshold.
[0063] By monitoring the execution time of the current task and the current task scheduling frame rate, the system effectively identifies situations where the current task has a low execution time and a long task interval, avoiding misidentification caused by relying solely on the scheduling of a single task or adjacent tasks, and accurately determining the working status of WebView.
[0064] Taking a scenario involving webpage loading with animation as an example, the first threshold corresponding to the task execution time T1 that does not affect animation loading is set to 40fps, the second threshold corresponding to the current task scheduling frame rate f that does not affect animation loading is set to 1 / 60s, and the third threshold corresponding to the first and second consecutive frame counts F1 and F2 that do not affect animation loading is set to 10 frames. When the global frequency limiting event listener function detects that the task execution time T1 is less than 40fps, it starts a frame count timer to determine the first consecutive frame count F1 when the task execution time T1 is less than 40fps; when the global frequency limiting event listener function detects that the current task scheduling frame rate f is less than 1 / 60s, it starts a frame count timer to determine the second consecutive frame count F2 when the current task scheduling frame rate f is less than 1 / 60s. When both the first consecutive frame count F1 and the second consecutive frame count F2 exceed the third threshold of 10 frames, it is determined that the WebView is in frequency limiting mode.
[0065] The following is another feasible embodiment for monitoring whether the WebView is in frequency-limiting mode. Unlike the previous feasible embodiment, which is based on monitoring the execution status of the WebView, this embodiment determines whether the WebView is in frequency-limiting mode by monitoring the status of the mobile terminal where the WebView is located.
[0066] Specifically, the client-side Native side monitors whether the mobile terminal has entered power saving mode or low power mode through the operating system API. When the mobile terminal is detected to have entered power saving mode or low power mode, the device's global frequency limiting event listener function, such as global_onFrequencyChanged, is notified through Native-to-JavaScript communication, and it is determined that the WebView has entered frequency limiting mode.
[0067] Another possible reason why the WebView's page refresh frequency might be lower than required is that the mobile device hosting the WebView is in power-saving or low-power mode. Occasionally, when the mobile device is in power-saving or low-power mode, the WebView's execution status might fail to promptly determine if it's in a frequency-limiting mode based on the execution time and frame rate of the current task. To avoid the operation of replacing the first scheduling timer with a second one only after the WebView has actually entered frequency-limiting mode, we introduce mobile device status monitoring. This compensates for the delayed frequency-limiting status identification caused by solely monitoring the WebView's execution status, proactively preventing potential page refresh stutters, and further avoiding brief stutters caused by delayed WebView execution status monitoring, effectively improving overall smoothness.
[0068] S103. If the WebView is in frequency limiting mode, the second scheduling timer is used to replace the first scheduling timer as the task scheduler of the WebView to refresh the webpage based on the WebView; otherwise, the first scheduling timer is used as the task scheduler of the WebView to refresh the webpage based on the WebView.
[0069] Figure 3 The flowchart illustrates, as an exemplary embodiment, a method for refreshing a WebView-based webpage using different scheduling timers based on the working state of the WebView.
[0070] Please refer to Figure 3 The method for refreshing the WebView-based webpage using different scheduling timers based on the WebView's working state includes:
[0071] S301. Determine the predetermined frame rate for the second scheduling timer to refresh the current webpage.
[0072] Before using the second scheduling timer to replace the first scheduling timer as the task scheduler of WebView to refresh the WebView-based webpage, the service with the highest refresh frequency among all services involved in the current WebView-based webpage is identified, and the lowest refresh frequency requirement of the service with the highest refresh frequency is used as the predetermined frame rate of the second scheduling timer.
[0073] The second scheduling timer can select from multiple fixed frame rates or a variable frame rate for refreshing the current webpage. Selecting from multiple fixed frame rates can be done by: having preset frame rates such as 60fps, 90fps, and 120fps corresponding to various service requirements; identifying the service with the highest refresh frequency requirement among all services involved in the current WebView-based webpage; and then selecting the closest matching fixed frame rate from the aforementioned preset fixed frame rates as the predetermined frame rate for the second scheduling timer. The variable frame rate method can be done by: identifying the service with the highest refresh frequency requirement among all services involved in the current WebView-based webpage; and then using the lowest refresh frequency requirement of the service with the highest actual refresh frequency requirement as the predetermined frame rate.
[0074] By dynamically determining the predetermined frame rate of the second scheduling timer based on the refresh requirements of the business involved in the currently refreshed webpage, the second scheduling timer can achieve smooth webpage loading with low power consumption without adding unnecessary losses while meeting the minimum requirement of no lag when using the second scheduling timer to perform refresh of Webview. This is especially suitable for application scenarios such as power saving mode and low power mode.
[0075] S302, Start the second scheduling timer.
[0076] Register a global task function name for the timer based on JavaScript, and communicate with Native via JavaScript based on the global task function name of the timer to start the second scheduling timer according to the predetermined frame rate.
[0077] S303, refresh the webpage based on the second scheduling timer.
[0078] After starting the second scheduling timer according to the predetermined frame rate, the Native task is scheduled according to the predetermined frame rate through CADisplayLink; during each Native scheduling, JavaScript is scheduled according to the predetermined frame rate through Native-to-JavaScript communication, so that the webpage is refreshed.
[0079] In summary, this embodiment solves the problem of the smoothness of web page animations and games being affected by the current task scheduling frame rate, the time taken to execute the current task, the number of frames that the above-mentioned situations occur continuously, and the mobile terminal where WebView is located entering power saving mode or low power mode. This is achieved by combining the method of calling the current task scheduling frame rate, the time taken to call the current task execution, the number of frames that the above-mentioned situations occur continuously, and the mobile terminal where WebView is located entering power saving mode or low power mode.
[0080] Understandably, when the WebView exits the frequency-limiting mode, it should revert to using the default requestAnimationFrame timer as the first timer for page refresh. The following is a flowchart of an example page refresh method when the WebView exits frequency-limiting mode. Figure 4 As shown.
[0081] Similar to determining whether a WebView has entered frequency-limiting mode, determining whether a WebView has exited frequency-limiting mode can also be done by monitoring the working status of the WebView and the status of the mobile terminal on which the WebView is located.
[0082] Please refer to Figure 4 Methods for WebView to refresh web pages out of frequency-limiting mode include:
[0083] S401. Monitor the working status of WebView and the status of the mobile terminal where WebView is located.
[0084] In some embodiments, when the second scheduling timer is used to replace the first scheduling timer as the task scheduler of WebView to refresh the webpage based on WebView, the working status of WebView and the status of the mobile terminal where WebView is located are continuously monitored.
[0085] In other embodiments, the client-side Native side monitors whether the mobile terminal has exited power saving mode or low power mode via the operating system API.
[0086] S402. If the WebView exits the frequency-limiting mode, the first scheduling timer is used as the task scheduler of the WebView to refresh the webpage based on the WebView when executing the next task.
[0087] In the embodiment of monitoring the working status of WebView to determine whether WebView has exited the frequency-limiting mode, the frequency of WebView calling empty functions is continuously monitored. If the frequency of WebView calling empty functions is greater than the fifth threshold, the first scheduling timer is used as the task scheduler of WebView to refresh the web page based on WebView when executing the next task.
[0088] Specifically, after switching to the second timer scheduler, the JavaScript side continuously monitors the frequency of calls to the JavaScript empty function by the WebView's native requestAnimationFrame. If the WebView requestAnimationFrame call frequency exceeds a specified threshold, such as 50fps, it is determined that the WebView has exited the low-battery / frequency-limiting mode. The JavaScript code then switches back to the WebView's requestAnimationFrame timer scheduler (which is the first timer scheduler) the next time requestAnimationFrame is called, and disables the native timer (which is the second timer scheduler). In addition to monitoring the call frequency of the WebView's native requestAnimationFrame calling the JavaScript empty function, similar to determining whether the WebView has entered the frequency-limiting mode, it can also determine whether the WebView has exited the frequency-limiting mode by monitoring the frame rate of the JavaScript empty function calls, the call duration, and the number of consecutive frames in which the above situations occur.
[0089] In the embodiment of monitoring the state of the mobile terminal where the WebView is located to determine whether the WebView has exited the frequency-limiting mode, if the state of the mobile terminal where the WebView is located exits the power-saving mode or low power mode, then when executing the next task, the first scheduling timer is used as the task scheduler of the WebView to refresh the web page based on the WebView.
[0090] Specifically, the Native side continuously monitors the operating system for exiting low power mode and power saving mode events. When it detects that the phone has exited low power mode or power saving mode events, it tells JavaScript through Native-to-JavaScript communication that it has exited power saving mode or low power frequency limiting mode. The JavaScript code then switches back to the WebView's requestAnimationFrame timer scheduler, which is the first scheduling timer, and closes the Native timer, which is the second scheduling timer, when it calls requestAnimationFrame again.
[0091] By continuously monitoring the working status of WebView and the status of the mobile terminal on which WebView is located, it is determined that WebView has exited the frequency-limiting mode. The custom scheduling timer with the refresh cycle determined based on business needs is promptly adjusted to the default scheduling timer of WebView to refresh the webpage, avoiding unnecessary scheduling waste.
[0092] Corresponding to the aforementioned WebView-based webpage refresh method, the present invention also provides a WebView-based webpage refresh device.
[0093] Figure 5 This is a schematic block diagram of a WebView-based webpage refresh device according to some exemplary embodiments of the present invention.
[0094] Please refer to Figure 5 A WebView-based webpage refresh device includes:
[0095] The scheduling timer 501 includes a first scheduling timer 5011 and a second scheduling timer 5012; wherein, the first scheduling timer 5011 is the default scheduling timer of WebView, and the second scheduling timer 5012 is a scheduling timer with a refresh cycle determined based on business needs;
[0096] Monitoring unit 502, the monitoring unit is configured to monitor the working status of WebView and the status of the mobile terminal where WebView is located;
[0097] The judgment and selection unit 503 is configured to perform the following actions: if the working state of the WebView is in the frequency limiting mode, then the second scheduling timer 5012 is used to replace the first scheduling timer 5011 as the task scheduler of the WebView to refresh the webpage based on the WebView; otherwise, the first scheduling timer 5011 is used as the task scheduler of the WebView to refresh the webpage based on the WebView. The frequency limiting mode is determined by monitoring the execution time and interval of the WebView's tasks, and by monitoring the state of the mobile terminal where the WebView is located.
[0098] The apparatus of this embodiment can be used to perform... Figure 1 The technical solutions of the method embodiments shown are similar in principle and in effect, and will not be described again here.
[0099] This application also provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the steps of any of the WebView-based webpage refresh methods provided in this application.
[0100] Specifically, computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, such as semiconductor memory devices (e.g., EPROM, EEPROM, and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD-ROM and DVD-ROM disks.
[0101] In summary, the WebView-based webpage refresh method provided by this invention can adaptively determine whether a mobile terminal's webpage has entered a frequency-limited state and automatically switch to a timer scheduler designed based on business needs for screen frame rate scheduling. This ensures that JavaScript can schedule tasks according to an approximate screen frame rate, making the upper-layer business unaffected, and the animation effects and game smoothness are not affected by power-saving or low-power modes. By monitoring and identifying whether the WebView has entered a frequency-limited mode and changing the scheduling timer, this invention ensures that the WebView in frequency-limited mode maintains the refresh frequency required by the business on the webpage. This solves the technical problems of poor page animation effects and low game smoothness in mobile terminal WebViews under frequency-limited states, improving the user experience while avoiding unnecessary power consumption.
[0102] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A webpage refresh method based on WebView, characterized in that, include: Set a first scheduling timer and a second scheduling timer; wherein, the first scheduling timer is the default scheduling timer of WebView, and the second scheduling timer is a scheduling timer with a refresh cycle determined based on business needs; Monitor the working status of WebView and the status of the mobile terminal where WebView is located; If the WebView is in frequency-limited mode, the second scheduling timer replaces the first scheduling timer as the WebView's task scheduler to refresh the WebView-based webpage. The status of the mobile terminal where the WebView is located is monitored. If the mobile terminal where the WebView is located exits power-saving mode or low-power mode, the first scheduling timer is used as the WebView's task scheduler to refresh the WebView-based webpage when executing the next task; otherwise, the first scheduling timer is used as the WebView's task scheduler to refresh the WebView-based webpage. The frequency limiting mode is determined by monitoring the execution time and interval of the WebView's tasks, as well as the status of the mobile terminal where the WebView is located.
2. The webpage refresh method based on WebView according to claim 1, characterized in that, The frequency limiting mode is determined by monitoring the execution time and interval of WebView tasks, including the following methods: Get the execution time T1 of the current task and the current scheduling interval T2 between the current task and the preceding adjacent task. The current task scheduling frame rate f is determined based on the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task; wherein, the current task scheduling frame rate f is inversely proportional to the current scheduling interval T2 between the execution of the current task and the execution of the preceding adjacent task. If the execution time T1 of the current task is less than the first threshold and the duration exceeds the third threshold, and the current task scheduling frame rate f is less than the second threshold and the duration exceeds the third threshold, then it is determined that WebView is in frequency limiting mode.
3. The webpage refresh method based on WebView according to claim 1, characterized in that, The frequency limiting mode is determined by monitoring the state of the mobile terminal where the WebView is located, including the following methods: By monitoring the status of the mobile terminal where the WebView is located through the operating system API, if the time the mobile terminal where the WebView is located is in power saving mode or low power mode exceeds the fourth threshold, it is determined that the mobile terminal where the WebView is located is in frequency limiting mode.
4. The webpage refresh method based on WebView according to claim 1, characterized in that, Before using the second scheduling timer to replace the first scheduling timer as the task scheduler of WebView to refresh the WebView-based webpage, the service with the highest required refresh frequency among all services involved in the current WebView-based webpage is identified, and the lowest refresh frequency requirement of the service with the highest required refresh frequency is used as the predetermined frame rate of the second scheduling timer.
5. The webpage refresh method based on WebView according to claim 1, characterized in that, The method of replacing the first scheduling timer with the second scheduling timer includes: Register a global task function name for a timer based on JavaScript; The second scheduling timer is started by communicating with Native via JavaScript based on the global task function name of the timer.
6. The webpage refresh method based on WebView according to claim 4, characterized in that, The method of replacing the first scheduling timer with the second scheduling timer as the task scheduler for WebView to refresh the WebView-based webpage includes: The second scheduling timer is started according to the predetermined frame rate, and the native task is scheduled according to the predetermined frame rate through CADisplayLink. During each Native scheduling, JavaScript is scheduled according to a predetermined frame rate through Native-to-JavaScript communication, causing the webpage to refresh.
7. The webpage refresh method based on WebView according to claim 1, characterized in that, When the second scheduling timer is used to replace the first scheduling timer as the task scheduler for WebView to refresh the webpage based on WebView, the frequency of WebView calling empty functions is monitored. If the frequency of WebView calling empty functions exceeds the fifth threshold, the first scheduling timer will be used as the task scheduler of WebView to refresh the webpage based on WebView when executing the next task.
8. The webpage refresh method based on WebView according to claim 1, characterized in that, When the second scheduling timer is used to replace the first scheduling timer as the task scheduler for WebView to refresh the webpage based on WebView, the status of the mobile terminal where WebView is located is monitored. If the mobile terminal where the WebView is located exits power saving mode or low power mode, the first scheduling timer is used as the task scheduler of the WebView to refresh the webpage based on the WebView when executing the next task.
9. A webpage refresh device based on WebView, characterized in that, include: The scheduling timer includes a first scheduling timer and a second scheduling timer; wherein the first scheduling timer is the default scheduling timer of WebView, and the second scheduling timer is a scheduling timer with a refresh cycle determined based on business needs; The monitoring unit is configured to monitor the working status of the WebView and the status of the mobile terminal where the WebView is located; The judgment and selection unit is configured to perform the following actions: if the WebView's working state is in frequency-limiting mode, then the second scheduling timer is used instead of the first scheduling timer as the WebView's task scheduler to refresh the WebView-based webpage; monitor the state of the mobile terminal where the WebView is located; if the mobile terminal where the WebView is located exits power-saving mode or low-power mode, then the first scheduling timer is used as the WebView's task scheduler to refresh the WebView-based webpage when executing the next task; otherwise, the first scheduling timer is used as the WebView's task scheduler to refresh the WebView-based webpage. The frequency limiting mode is determined by monitoring the execution time and interval of the WebView's tasks, as well as the status of the mobile terminal where the WebView is located.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that... When the program is executed by the processor, it implements the steps of the WebView-based webpage refresh method according to any one of claims 1-8.
Citation Information
Patent Citations
Method and device for controlling content to be refreshed in real time
CN108228300A
Page loading time length detection method and device, equipment and storage medium
CN110287441A