Keep-alive method and device for background service processTechnical Field
The invention relates to the field of computers, in particular to a keep-alive method and a keep-alive device for a background service process.
Background
Analysis shows that the background service process is easily killed by the system or third-party software due to low priority, so that unexpected interruption or restart is easily caused, and the unexpected interruption or restart of the process can cause adverse effects on services such as data push or download.
Analysis also finds that there are 2 main reasons why the background service process is easily killed, which are: (1) background service processes are low in priority, and a system (such as an Android system) adopting an Object-Oriented Method (OOM) mechanism can automatically kill the processes with low priority when the memory is tight, so that enough space is reserved to ensure the processes with high priority to normally run; (2) most users, especially Android users, consciously clean background applications (i.e., background service processes), and a system (e.g., an Android system) or third-party cleaning software generally provides a convenient one-key background application cleaning function.
In order to keep the background service process alive to the maximum extent, currently, the following 2 methods are commonly adopted by hot applications of some large companies: (1) after the process is killed, restarting the killed process by using an independent daemon process, or calling up the killed process by using third-party software, or awakening the killed process by using a system alarm clock, static broadcast and the like; (2) because the priority of the foreground service process is higher than that of the background service process, the invisible background service process is set as the visible foreground service process to improve the priority of the process, thereby preventing the system or third-party software from killing the process too early and realizing the purpose of keeping the background service process alive.
In the method (1), the process is only activated again after death, and the purpose of keeping alive cannot be achieved substantially; with regard to the method (2), although the keep-alive purpose can be achieved well, when the foreground service process is set, the system API will inevitably require the foreground service process to bind the notification bar to one notification. For the notification, on the one hand, the user cannot clear the notification directly, which may cause most of the user to be dislike; on the other hand, when the user clears the notification by using third-party software and other means, the foreground service process is necessarily cancelled, and the cancellation of the foreground service process is equal to the killing of the corresponding background service process.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the invention provides a keep-alive method and a keep-alive device for a background service process, which are used for at least solving the technical problem that in the related art, a foreground service process is independently bound on a notification, so that the foreground service process having a binding relation with the notification is inevitably cancelled when the notification is cleared, and further the background service process corresponding to the foreground service process is inevitably killed.
According to an aspect of the embodiments of the present invention, a keep-alive method for a background service process is provided, including: acquiring a foreground temporary service process, wherein the foreground temporary service process is configured by a background temporary service process, the foreground temporary service process and a foreground resident service process are bound on a notification, the foreground resident service process is configured by a background resident service process, the notification is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; clearing the notification bound with the foreground temporary service process.
According to another aspect of the embodiments of the present invention, there is also provided a keep-alive device for a background service process, including: an obtaining unit, configured to obtain a foreground temporary service process, where the foreground temporary service process is configured by a background temporary service process, and the foreground temporary service process and a foreground resident service process are bound to a notification, where the foreground resident service process is configured by a background resident service process, the notification is used to prompt that the foreground temporary service process and the foreground resident service process are running in a foreground, and a priority of the foreground resident service process is higher than a priority of the background resident service process; a first closing unit, configured to close the foreground temporary service process; and the clearing unit is used for clearing the notice bound with the foreground temporary service process.
In the embodiment of the invention, a mode that two foreground service processes obtained by respectively configuring two background service processes are bound on the same notice is adopted, and a foreground temporary service process is obtained, wherein the foreground temporary service process is obtained by configuring the background temporary service processes, the foreground temporary service process and a foreground resident service process are bound on one notice, the foreground resident service process is obtained by configuring the background resident service processes, the notice is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; the notice bound with the foreground temporary service process is cleared to keep the background service process alive, because the system automatically clears the notice bound with the foreground temporary service process from the notice column after the temporary service process is closed, and after the notice is cancelled, a user cannot easily perceive the resident service process running on the foreground with high priority, and the user cannot actively check and kill the process (or the processes) only if the user cannot perceive that the resident service process is running, so that the aim of sacrificing the temporary service process to prevent the user from actively checking and killing the resident service process running on the foreground with high priority is achieved, the technical effect of keeping the resident service process running on the foreground with high priority is realized, and the problem that the foreground service process is independently bound on one notice in the related technology, so that the foreground service process bound with the notice is inevitably cancelled when the notice is cleared, and further the background service process corresponding to the foreground service process is inevitably killed.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is a block diagram of a hardware structure of a computer terminal of a keep-alive method of a background service process according to an embodiment of the present invention;
FIG. 2 is a flow diagram of an alternative keep-alive method for a background service process, according to an embodiment of the invention;
FIG. 3 is a logical relationship diagram of an alternative foreground and background service process according to an embodiment of the invention;
fig. 4 is a schematic diagram of a keep-alive device for an optional background service process according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1
There is also provided, in accordance with an embodiment of the present invention, an embodiment of a keep-alive method for a background service process, it being noted that the steps illustrated in the flowchart of the drawings may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
The method provided by the first embodiment of the present application may be executed in a mobile terminal, a computer terminal, or a similar computing device. Taking the example of running on a computer terminal, fig. 1 is a block diagram of a hardware structure of a computer terminal of a keep-alive method of a background service process according to an embodiment of the present invention. As shown in fig. 1, the computer terminal 10 may include one or more (only one shown) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the electronic device. For example, the computer terminal 10 may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be configured to store software programs and modules of application software, such as program instructions/modules corresponding to the keep-alive method of the background service process in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implements the vulnerability detection method of the application program. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used for receiving or transmitting data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 can be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
Under the above operating environment, the present application provides a keep-alive method for a background service process as shown in fig. 2. Fig. 2 is a flowchart of an optional keep-alive method for a background service process according to an embodiment of the present invention, and as shown in fig. 2, the method includes the following steps:
step S202, a foreground temporary service process is obtained, wherein the foreground temporary service process is obtained by configuration of a background temporary service process and is bound to a notification of the foreground resident service process, the foreground resident service process is obtained by configuration of a background resident service process, the notification is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process;
step S204, closing the foreground temporary service process;
step S206, the notice bound with the foreground temporary service process is cleared, so as to keep the background service process alive.
That is, the temporary service process and the resident service process running on the background are respectively configured into a corresponding temporary service process and a corresponding resident service process running on the foreground, and the temporary service process and the resident service process running on the foreground are bound on a notice for prompting the user that the service processes running on the foreground exist, so that if the foreground running state of the temporary service process is cancelled, the system automatically clears the notice bound with the temporary service process from the notice bar, in this case, because the notice bound with the foreground resident service process is cleared, the user is difficult to perceive that the system actually runs the foreground resident service process (namely, the foreground resident service process is still alive), thereby the foreground resident service process cannot be initiatively killed, the corresponding background service process cannot be killed, namely, the foreground temporary service process is closed and the corresponding notice is cleared, the resident service is not influenced at all and can normally run on the foreground, so that the high priority of the foreground running state of the resident service process is kept, the bound notification is closed based on the reason, and the user cannot perceive that the resident service is running on the foreground at the moment, so that the resident service or the resident services cannot be actively cleaned.
It should be noted that, in the embodiment of the present invention, a background service process may be configured as a corresponding foreground service process configuration in the following manner: in order to configure a background temporary service process as a corresponding foreground temporary service process, in implementation, the background temporary service process may be declared and started first, and then a system API "startformed" is called to set the background temporary service process as a foreground temporary service process; in an embodiment of configuring the background resident service process as the corresponding foreground resident service process, the background resident service process may be started first, and then the system API "startformed" may be called to set the background resident service process as the foreground resident service process. The logical relationship between the foreground and background service processes is shown in fig. 3. Because the foreground temporary service process and the foreground resident service process are both bound on one notice, the notice is clear by closing the foreground temporary service process, and a user is difficult to find that the system runs the foreground resident service process, so that the foreground resident service process cannot be actively searched and killed, and the aim of keeping the foreground resident service process alive by clearly corresponding notice of the foreground temporary service process is fulfilled.
In the embodiment of the invention, a mode that two foreground service processes obtained by respectively configuring two background service processes are bound on the same notice is adopted, and the foreground temporary service process is obtained by configuring the background temporary service process and bound on a notice together with the foreground resident service process, the foreground resident service process is obtained by configuring the background resident service process, the notice is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; the notice bound with the foreground temporary service process is cleared to keep the background service process alive, because the system automatically clears the notice bound with the foreground temporary service process from the notice column after the temporary service process is closed, and after the notice is cancelled, a user cannot easily perceive the resident service process running on the foreground with high priority, and the user cannot actively check and kill the process (or the processes) only if the user cannot perceive that the resident service process is running, so that the aim of sacrificing the temporary service process to prevent the user from actively checking and killing the resident service process running on the foreground with high priority is achieved, the technical effect of keeping the resident service process running on the foreground with high priority is realized, and the problem that the foreground service process is independently bound on one notice in the related technology, so that the foreground service process bound with the notice is inevitably cancelled when the notice is cleared, and further the background service process corresponding to the foreground service process is inevitably killed.
Optionally, before acquiring the foreground temporary service process, the method further includes:
s2, starting the background resident service process, configuring the foreground resident service process according to the background resident service process, and binding the foreground resident service process on the notice;
s4, starting the background temporary service process and configuring the foreground temporary service process according to the background temporary service process, and binding the foreground temporary service process on the notice.
For example, a background resident service process a of the PP assistant is started, the background resident service process is set as a foreground resident service process, the foreground resident service process is bound to a notification C, and a temporary service process B is started at the same time, the temporary service process B is a background process, and in order to ensure that the platform resident service process a is alive to the maximum extent, after the temporary service process B is started, the temporary service process B needs to be set as a foreground service process, namely a foreground temporary service process, and the foreground temporary service process is bound to the notification C, and the foreground running state of the temporary service process B is immediately cancelled, namely the foreground temporary service process is cancelled. Because the foreground temporary service process is bound on the notice C, and after the foreground temporary service process is cancelled, the android system can automatically clear the notice C in the notice bar. Since the whole process is in millisecond order, the user has not seen the notification C of the foreground resident service process a and the foreground temporary service process B in step S204 is shown in the notification bar, and the notification C has been removed by the operation in step S206. Therefore, the embodiment of the invention simply and silently forms a resident service which is not sensed by a user and has a foreground running state by skillfully utilizing the defect of system code logic, and the service enables the process to which the service belongs to become a foreground visible process, thereby improving the priority, avoiding the system from killing the foreground visible process too early and further achieving the maximum keep-alive effect.
Optionally, before starting the background temporary service process, the method further includes:
s6, defining a null service process;
and S8, declaring the empty service process as a background temporary service process.
For example, a background resident service process A is set as a foreground service process and bound with a notification C, then a background temporary service process B is declared and started, the background temporary service process B is also set as a foreground service process and bound with the notification C, so that 2 foreground service processes are bound on the same notification, then a service closing function API "stopService" is called to cancel the foreground running state of the background temporary service process B, and the background temporary service process B is closed, at the moment, an android system can simultaneously remove the notification C bound with the background temporary service B in a notification bar, but the normal running of the background resident service process A is not influenced by the operations, the high priority of the foreground service of the background resident service process A can still be maintained, and meanwhile, the notification bar does not have the prompt information of the process, so that the background service can be prevented from being checked and killed by a user based on notification prompt after the priority is improved The effect is that the purpose of keeping alive the resident service is realized.
In addition, the background temporary service process is defined as an empty service process, namely, the process does not provide any substantial operation during running, so that the whole programming process can be simplified, and the cost consumption is reduced.
Optionally, configuring the foreground resident service process according to the background resident service process includes: calling a foreground running state starting function to configure a background resident service process with a foreground resident service process; configuring the foreground temporary service process according to the background temporary service process comprises the following steps: calling a foreground running state starting function to configure a background temporary service process to a foreground temporary service process; closing the foreground temporary service process comprises: and calling a foreground running state closing function to close the foreground temporary service process.
For example, a background resident service process a is started, a system API "startforego" is called to set the background resident service process a as a foreground resident service process, and the foreground resident service process is bound to a notification C; declaring and starting a background temporary service process B, calling a system API (API) startForeground to set the background temporary service process B as a foreground temporary service process, and simultaneously binding the foreground temporary service process on a notice C, so that the background resident service process and the background temporary service process are bound on the same notice C. Correspondingly, when a foreground temporary service process corresponding to a background temporary service process is cancelled, the system API ' stopPereground ' (true) ' can be called to cancel the foreground running state of the background temporary service process B, namely, cancel the foreground temporary service process, and at the moment, the system can remove the notice C bound with the foreground temporary service process from the notice board. The technical scheme can not influence the normal operation of the resident service, still keeps the high priority of the foreground service of the background resident service process A, simultaneously can not generate any prompt message of the foreground resident service process in the notification bar, and achieves the technical effect of improving the priority of the background service under the silent condition to keep the background service alive.
Optionally, while closing the foreground temporary service process, the method further includes:
and S10, closing the background temporary service process corresponding to the foreground temporary service process.
For example, the background resident service process A is set as the foreground service process and bound with the notice C, then a background temporary service process B is started, the background temporary service process B is also set as the foreground service process and bound with the notice C, so that 2 foreground service processes are bound with the same notice, then, the foreground running state of the background temporary service process B is cancelled and the background temporary service process B is closed, at this time, the android system will simultaneously clear the notification C bound with the background temporary service B in the notification bar, but the operation does not affect the normal operation of the background resident service process A, and can still maintain the high priority of the foreground service of the background resident service process A, and simultaneously, the notification bar does not have the prompt message of the process, therefore, the technical effect of improving the background service priority to keep the corresponding background service alive in a silent mode is achieved. The silence is to set the target background service as foreground service, raise the process priority to keep the target background service alive for the foreground visible process, and meanwhile, no notification bar is needed to be associated for notification prompt, so that the user is unaware in the whole process.
Optionally, the closing the background temporary service process corresponding to the foreground temporary service process includes:
s12, calling a background service closing function;
and S14, running a background service closing function to close the background temporary service process corresponding to the foreground temporary service process.
For example, the background resident service process A is set as the foreground service process and bound with the notice C, then a background temporary service process B is started, the background temporary service process B is also set as the foreground service process and bound with the notice C, so that 2 foreground service processes are bound with the same notice, then, calling a service closing function API 'stopServer' to cancel the foreground running state of the background temporary service process B and close the background temporary service process B, at this time, the android system will simultaneously clear the notification C bound with the background temporary service B in the notification bar, but the operation does not affect the normal operation of the background resident service process A, and can still maintain the high priority of the foreground service of the background resident service process A, and simultaneously, the notification bar does not have the prompt message of the process, therefore, the technical effect of improving the background service priority to keep the corresponding background service alive in a silent mode is achieved.
It should be noted that the technical solution of the present invention has been tried in a PP helper client of an android application distribution center, and a trial result shows that the technical solution can improve the survival rate of a background service process and prolong the survival time, so that the stability of services such as pushing and downloading can be improved.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Through the above description of the embodiments, those skilled in the art can clearly understand that the keep-alive method of the background service process according to the above embodiments can be implemented by software plus a necessary general hardware platform, and of course, may also be implemented by hardware, but the former is a better implementation in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Example 2
According to an embodiment of the present invention, there is further provided a device for implementing the keep-alive method for the background service process, as shown in fig. 4, the device includes: an obtaining unit 402, configured to obtain a foreground temporary service process, where the foreground temporary service process is obtained by configuring a background temporary service process, and the foreground temporary service process and a foreground resident service process are bound to a notification, the foreground resident service process is obtained by configuring a background resident service process, the notification is used to prompt that the foreground temporary service process and the foreground resident service process are running in a foreground, and a priority of the foreground resident service process is higher than a priority of the background resident service process; a first closing unit 404, configured to close a foreground temporary service process; a clearing unit 406, configured to clear the notification bound with the foreground temporary service process to keep alive the background service process.
That is, the temporary service process and the resident service process running on the background are respectively configured into a corresponding temporary service process and a corresponding resident service process running on the foreground, and the temporary service process and the resident service process running on the foreground are bound on a notice for prompting the user that the service processes running on the foreground exist, so that if the foreground running state of the temporary service process is cancelled, the system automatically clears the notice bound with the temporary service process from the notice bar, in this case, because the notice bound with the foreground resident service process is cleared, the user is difficult to perceive that the system actually runs the foreground resident service process (namely, the foreground resident service process is still alive), thereby the foreground resident service process cannot be initiatively killed, the corresponding background service process cannot be killed, namely, the foreground temporary service process is closed and the corresponding notice is cleared, the resident service is not influenced at all and can normally run on the foreground, so that the high priority of the foreground running state of the resident service process is kept, the bound notification is closed based on the reason, and the user cannot perceive that the resident service is running on the foreground at the moment, so that the resident service or the resident services cannot be actively cleaned.
It should be noted that, in the embodiment of the present invention, a background service process may be configured as a corresponding foreground service process configuration in the following manner: in order to configure a background temporary service process as a corresponding foreground temporary service process, in implementation, the background temporary service process may be declared and started first, and then a system API "startformed" is called to set the background temporary service process as a foreground temporary service process; in an embodiment of configuring the background resident service process as the corresponding foreground resident service process, the background resident service process may be started first, and then the system API "startformed" may be called to set the background resident service process as the foreground resident service process.
In the embodiment of the invention, a mode that two foreground service processes obtained by respectively configuring two background service processes are bound on the same notice is adopted, and the foreground temporary service process is obtained by configuring the background temporary service process and bound on a notice together with the foreground resident service process, the foreground resident service process is obtained by configuring the background resident service process, the notice is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; the notice bound with the foreground temporary service process is cleared to keep the background service process alive, because the system automatically clears the notice bound with the foreground temporary service process from the notice column after the temporary service process is closed, and after the notice is cancelled, a user cannot easily perceive the resident service process running on the foreground with high priority, and the user cannot actively check and kill the process (or the processes) only if the user cannot perceive that the resident service process is running, so that the aim of sacrificing the temporary service process to prevent the user from actively checking and killing the resident service process running on the foreground with high priority is achieved, the technical effect of keeping the resident service process running on the foreground with high priority is realized, and the problem that the foreground service process is independently bound on one notice in the related technology, so that the foreground service process bound with the notice is inevitably cancelled when the notice is cleared, and further the background service process corresponding to the foreground service process is inevitably killed.
Optionally, the apparatus further comprises: the first processing unit is used for starting a background resident service process, configuring a foreground resident service process according to the background resident service process and binding the foreground resident service process on the notice before acquiring the foreground temporary service process; and the second processing unit is used for starting the background temporary service process, configuring the foreground temporary service process according to the background temporary service process and binding the foreground temporary service process to the notice.
Optionally, the apparatus further comprises: the defining unit is used for defining an empty service process before the background temporary service process is started; and the declaration unit is used for declaring the empty service process as a background temporary service process.
Optionally, the first processing unit is further configured to: calling a foreground running state starting function to configure a background resident service process with a foreground resident service process; the second processing unit is further configured to: calling a foreground running state starting function to configure a background temporary service process to a foreground temporary service process; the first closing unit is further configured to: and calling a foreground running state closing function to close the foreground temporary service process.
Optionally, the apparatus further comprises: and the second closing unit is also used for closing the background temporary service process corresponding to the foreground temporary service process while closing the foreground temporary service process.
Optionally, the second closing unit includes: the calling module is used for calling a background service closing function; and the running module is used for running the background service closing function so as to close the background temporary service process corresponding to the foreground temporary service process.
It should be noted that, the embodiments of the apparatus portion are the same as or similar to the embodiments of the method portion, and the applicant does not reiterate here, and at the same time, the functions implemented by the units/modules in the embodiments of the apparatus portion are the same as or similar to the functions implemented by the corresponding steps in the embodiments of the method portion, and the applicant does not reiterate here.
Example 3
The embodiment of the invention can provide a computer terminal which can be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal may also be replaced with a terminal device such as a mobile terminal.
Optionally, in this embodiment, the computer terminal may be located in at least one network device of a plurality of network devices of a computer network.
In this embodiment, the computer terminal may execute program codes of the following steps in the keep-alive method of the background service process of the application program: acquiring a foreground temporary service process, wherein the foreground temporary service process is obtained by the configuration of a background temporary service process, the foreground temporary service process and a foreground resident service process are bound on a notification, the foreground resident service process is obtained by the configuration of the background resident service process, the notification is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; and clearing the notice bound with the foreground temporary service process so as to keep the background service process alive.
Optionally, the computer terminal (labeled as computer terminal a) may include: one or more processors (only one of which is shown), memory, and other components.
The memory may be configured to store a software program and a module, such as program instructions/modules corresponding to the keep-alive method and apparatus for the background service process in the embodiment of the present invention, and the processor executes various functional applications and data processing by running the software program and the module stored in the memory, that is, implements the keep-alive method for the background service process. The memory may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory may further include memory remotely located from the processor, and these remote memories may be connected to terminal a through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The processor can call the information and application program stored in the memory through the transmission device to execute the following steps: and after the foreground temporary service process corresponding to the background temporary service process is cancelled, closing the background temporary service process.
Optionally, the processor may further execute the program code of the following steps: before the foreground temporary service process is acquired, starting a background resident service process, configuring a foreground resident service process according to the background resident service process, and binding the foreground resident service process on a notice; starting the background temporary service process, configuring the foreground temporary service process according to the background temporary service process, and binding the foreground temporary service process on the notice.
Optionally, the processor may further execute the program code of the following steps: before starting the background temporary service process, the method further comprises: defining an empty service process; and declaring the empty service process as a background temporary service process.
Optionally, the processor may further execute the program code of the following steps: calling a foreground running state starting function to configure a background resident service process with a foreground resident service process; calling a foreground running state starting function to configure a background temporary service process to a foreground temporary service process; and calling a foreground running state closing function to close the foreground temporary service process.
Optionally, the processor may further execute the program code of the following steps: and closing the background temporary service process corresponding to the foreground temporary service process while closing the foreground temporary service process.
Optionally, the processor may further execute the program code of the following steps: calling a background service closing function; and running a background service closing function to close the background temporary service process corresponding to the foreground temporary service process.
In the embodiment of the invention, a mode that two foreground service processes are bound with the same notice is adopted, and the foreground temporary service processes are obtained by configuration of the background temporary service processes and are bound with the foreground resident service processes on a notice, the foreground resident service processes are obtained by configuration of the background resident service processes, the notice is used for prompting that the foreground temporary service processes and the foreground resident service processes are running in the foreground, and the priority of the foreground resident service processes is higher than that of the background resident service processes; closing the foreground temporary service process; the method and the device have the advantages that the notification bound with the foreground temporary service process is cleared, the background service process is kept alive, the purpose of clearing the notification by using the temporary service process is achieved, the user aversion is prevented, the technical effect that the resident process is killed is avoided, and the technical problem that in the related technology, the foreground service process is bound on one notification independently, the notification is cleared, the foreground service process with the binding relation with the notification is cancelled, and the background service process corresponding to the foreground service process is killed is solved.
It can be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration, and the computer terminal may also be a terminal device such as a smart phone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a palmtop computer, a Mobile Internet Device (MID), a PAD, and the like. Fig. 1 is a diagram illustrating a structure of the electronic device. For example, the computer terminal 10 may also include more or fewer components (e.g., network interfaces, display devices, etc.) than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by a program instructing hardware associated with the terminal device, where the program may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), magnetic or optical disks, and the like.
Example 4
The embodiment of the invention also provides a storage medium. Optionally, in this embodiment, the storage medium may be configured to store program codes executed by the keep-alive method of the background service process provided in embodiment 1.
Optionally, in this embodiment, the storage medium may be located in any one of computer terminals in a computer terminal group in a computer network, or in any one of mobile terminals in a mobile terminal group.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: acquiring a foreground temporary service process, wherein the foreground temporary service process is obtained by the configuration of a background temporary service process, the foreground temporary service process and a foreground resident service process are bound on a notification, the foreground resident service process is obtained by the configuration of the background resident service process, the notification is used for prompting that the foreground temporary service process and the foreground resident service process are running in the foreground, and the priority of the foreground resident service process is higher than that of the background resident service process; closing the foreground temporary service process; and clearing the notice bound with the foreground temporary service process so as to keep the background service process alive.
Optionally, in this embodiment, the storage medium is further configured to store program code for performing the following steps: before the foreground temporary service process is acquired, starting a background resident service process, configuring a foreground resident service process according to the background resident service process, and binding the foreground resident service process on a notice; starting the background temporary service process, configuring the foreground temporary service process according to the background temporary service process, and binding the foreground temporary service process on the notice.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: before starting the background temporary service process, the method further comprises: defining an empty service process; and declaring the empty service process as a background temporary service process.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: calling a foreground running state starting function to configure a background resident service process with a foreground resident service process; calling a foreground running state starting function to configure a background temporary service process to a foreground temporary service process; and calling a foreground running state closing function to close the foreground temporary service process.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: and closing the background temporary service process corresponding to the foreground temporary service process while closing the foreground temporary service process.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: calling a background service closing function; and running a background service closing function to close the background temporary service process corresponding to the foreground temporary service process.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.