CN107231386B - Application state conversion method and device and mobile terminal - Google Patents
Application state conversion method and device and mobile terminal Download PDFInfo
- Publication number
- CN107231386B CN107231386B CN201610167883.4A CN201610167883A CN107231386B CN 107231386 B CN107231386 B CN 107231386B CN 201610167883 A CN201610167883 A CN 201610167883A CN 107231386 B CN107231386 B CN 107231386B
- Authority
- CN
- China
- Prior art keywords
- application
- state
- background
- operating system
- timing task
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/54—Presence management, e.g. monitoring or registration for receipt of user log-on information, or the connection status of the users
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04M—TELEPHONIC COMMUNICATION
- H04M1/00—Substation equipment, e.g. for use by subscribers
- H04M1/72—Mobile telephones; Cordless telephones, i.e. devices for establishing wireless links to base stations without route selection
- H04M1/724—User interfaces specially adapted for cordless or mobile telephones
- H04M1/72448—User interfaces specially adapted for cordless or mobile telephones with means for adapting the functionality of the device according to specific conditions
- H04M1/72451—User interfaces specially adapted for cordless or mobile telephones with means for adapting the functionality of the device according to specific conditions according to schedules, e.g. using calendar applications
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Human Computer Interaction (AREA)
- Information Transfer Between Computers (AREA)
- Telephone Function (AREA)
Abstract
The invention discloses an application state conversion method, an application state conversion device and a mobile terminal, and belongs to the technical field of terminals. The method comprises the following steps: starting an application, wherein the application configures a VoIP function through a VoIP background interface provided by an operating system; when determining that the application starts to be converted from the running state to the non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state; registering a timing task to an operating system in the process of restarting the application, wherein the timing task is used for indicating the operating system to periodically wake up the application in a suspended state; according to the timing task, the application in the suspended state is awakened periodically, and the awakened application is in a background state. The invention solves the problem that the application cannot reside in the background because the application is killed or exited by the iOS and enters the non-running state.
Description
Technical Field
The present invention relates to the field of terminal technologies, and in particular, to an application state transition method and apparatus, and a mobile terminal.
Background
With the continuous development of mobile operating systems, applications (applications) in the mobile operating systems are increasingly required to run in the background. In order to enable the application to run in the background, the mobile operating system needs to provide a corresponding background technical interface for the application to call.
In the related art, background technical interfaces provided by a mobile operating system (iOS) developed by apple inc include a Voice over Internet Protocol (VoIP) background interface, a music playing background interface, a positioning service background interface, and a background task application interface, and an application can be run in a background state (background) by calling a corresponding background task interface.
Currently, an application running in the background state will enter the not running state (not running) for various reasons (e.g., killed by the iOS because of frequent awakenings, or exited by the iOS beyond a set duration), resulting in the application not being able to reside in the background.
Disclosure of Invention
In order to solve the problem that the application cannot reside in the background because the application is killed or exited by the iOS and enters an idle state in the related art, embodiments of the present invention provide an application state conversion method, an application state conversion apparatus, and a mobile terminal. The technical scheme is as follows:
in a first aspect, an application state transition method is provided, where the method is used in a mobile terminal, an operating system is installed in the mobile terminal, and at least one application is installed in the operating system, and the method includes:
starting the application, wherein the application configures VoIP functions through a VoIP background interface provided by the operating system;
when the application is determined to start to be converted from a running state to a non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state;
registering a timing task with the operating system in the process of restarting the application, wherein the timing task is used for indicating the operating system to periodically wake up the application in a suspended state;
and according to the timing task, periodically waking up the application in the suspended state, wherein the application after being woken up is in a background state.
The VoIP function is configured for the application in advance, so that a buffer period exists when the application is converted from the running state to the non-running state, the application is automatically restarted and registers the timing task to the operating system by using the buffer period, the operating system can periodically wake up the application which is in the suspended state after being restarted according to the timing task, and the application is resident in the background.
With reference to the first aspect, in a first possible implementation manner of the first aspect, when the application is in the foreground state, the method further includes:
when a predetermined operation is detected, converting the application from the foreground state to the suspended state;
waking up the application in the suspended state by a predetermined wake-up mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
When a user performs specific operation on the mobile terminal, so that the application is converted from a foreground state to a suspended state, the application is awakened from the suspended state through a data push awakening mode or a timing task awakening mode, and background resident of the application is realized.
With reference to the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, when the application is woken up by the data push wake-up manner, the waking up the application in the suspended state by the predetermined wake-up manner includes:
and when receiving data pushed to the application by an application server, waking up the application in the suspended state.
When the application with the VoIP function is in the suspended state, the terminal takes over the connection between the application servers, and when the data sent by the application servers are received, the application in the suspended state is awakened, so that the application can process the received data in time.
With reference to the first possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, when the application is woken up by the timed task wake-up manner, the starting the application includes:
registering the timed task with the operating system in the process of starting the application;
the waking up the application in the suspended state by a predetermined waking up mode includes:
and according to the timing task, periodically waking up the application in the suspended state.
In order to avoid that the application is killed or quitted by the operating system due to the fact that the application is in the suspended state for a long time, the application registers the timing task in the starting stage, when the application is in the suspended state, the operating system wakes up the application regularly according to the timing task, the application is prevented from being killed or quitted by the operating system, and therefore background resident of the application is achieved.
With reference to the first aspect, the first possible implementation manner of the first aspect, the second possible implementation manner of the first aspect, or the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, the application after waking up is transitioned back to the suspended state after maintaining the background state for the first duration.
The awakened application enters the suspended state again after maintaining the background state for a period of time, so that the application can run in the background, and the shortage of processing resources caused by the fact that the application occupies the background for a long time is avoided.
With reference to the first possible implementation manner of the first aspect, the second possible implementation manner of the first aspect, or the third possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, after the converting the application from the foreground state to the suspended state, the method further includes:
receiving a background task application sent by the application in a process of converting from a foreground state to a background state, wherein the background task application is used for requesting the operating system to allow the application to maintain the background state for a second duration;
and when the second duration is over, converting the application from the background state to the suspended state.
And the application applies for the background running time of the second duration and actively stops code execution when the second duration is reached, so that the operating system can convert the application from the background state to the suspended state. The application can be prevented from being killed by an operating system due to exceeding the limit while acquiring the extra background running time, so that the application is ensured to be resident in the background.
In a second aspect, an application state transition apparatus is provided, where the apparatus includes at least one unit, where the at least one unit is configured to implement the application state transition method provided in the first aspect or the possible implementation manner of the first aspect, and the application state transition apparatus includes:
the starting unit is used for starting the application, and the application configures a VoIP function through a VoIP background interface of the network voice call provided by the operating system;
the restarting unit is used for restarting the application before the conversion is completed when the application is determined to start to convert from the running state to the non-running state, wherein the running state comprises a foreground state or a background state;
the registering unit is used for registering a timing task to the operating system in the process of restarting the application, and the timing task is used for indicating the operating system to periodically wake up the application in a suspended state;
and the awakening unit is used for periodically awakening the application in the suspended state according to the timing task, and the awakened application is in the background state.
The VoIP function is configured for the application in advance, so that a buffer period exists when the application is converted from the running state to the non-running state, the application is automatically restarted and registers the timing task to the operating system by using the buffer period, the operating system can periodically wake up the application which is in the suspended state after being restarted according to the timing task, and the application is resident in the background.
With reference to the second aspect, in a first possible implementation manner of the second aspect, the apparatus includes:
a conversion unit configured to convert the application from the foreground state to the suspended state when a predetermined operation is detected;
the awakening unit is further used for awakening the application in the suspended state through a preset awakening mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
When a user performs specific operation on the mobile terminal, so that the application is converted from a foreground state to a suspended state, the application is awakened from the suspended state through a data push awakening mode or a timing task awakening mode, and background resident of the application is realized.
With reference to the first possible implementation manner of the second aspect, in a second possible implementation manner of the second aspect, when the application is woken up by the data pushing wake manner, the wake unit is configured to wake up the application in the suspended state when data pushed to the application by an application server is received.
When the application with the VoIP function is in the suspended state, the terminal takes over the connection between the application servers, and when the data sent by the application servers are received, the application in the suspended state is awakened, so that the application can process the received data in time.
With reference to the first possible implementation manner of the second aspect, in a third possible implementation manner of the second aspect, when the application is woken up by the timed task wake-up manner; the starting unit is further used for registering the timing task to the operating system in the process of starting the application;
the awakening unit is further configured to periodically awaken the application in the suspended state according to the timing task.
In order to avoid that the application is killed or quitted by the operating system due to the fact that the application is in the suspended state for a long time, the application registers the timing task in the starting stage, when the application is in the suspended state, the operating system wakes up the application regularly according to the timing task, the application is prevented from being killed or quitted by the operating system, and therefore background resident of the application is achieved.
With reference to the second aspect, the first possible implementation manner of the second aspect, the second possible implementation manner of the second aspect, or the third possible implementation manner of the second aspect, in a fourth possible implementation manner of the second aspect, the application after waking up is transitioned back to the suspended state after maintaining the background state for the first duration.
The awakened application enters the suspended state again after maintaining the background state for a period of time, so that the application can run in the background, and the shortage of processing resources caused by the fact that the application occupies the background for a long time is avoided.
With reference to the first possible implementation manner of the second aspect, the second possible implementation manner of the second aspect, or the third possible implementation manner of the second aspect, in a fifth possible implementation manner of the second aspect, the apparatus further includes:
a receiving unit, configured to receive a background task application sent by the application in a process of converting from a foreground state to a background state, where the background task application is used to request the operating system to allow the application to maintain the background state for a second duration;
the conversion unit is further configured to convert the application from the background state to the suspended state when the second duration is over.
And the application applies for the background running time of the second duration and actively stops code execution when the second duration is reached, so that the operating system can convert the application from the background state to the suspended state. The application can be prevented from being killed by an operating system due to exceeding the limit while acquiring the extra background running time, so that the application is ensured to be resident in the background.
In a third aspect, a mobile terminal is provided, which includes: a processor and a memory coupled to the processor, wherein the memory is configured to store one or more instructions configured to be executed by the processor; the processor is configured to implement the application state transition method provided in the first aspect or in a possible implementation of the first aspect by executing instructions in the memory, and is configured to:
starting the application, wherein the application configures VoIP functions through a VoIP background interface provided by the operating system;
when the application is determined to start to be converted from a running state to a non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state;
registering a timing task with the operating system in the process of restarting the application, wherein the timing task is used for indicating the operating system to periodically wake up the application in a suspended state;
and according to the timing task, periodically waking up the application in the suspended state, wherein the application after being woken up is in a background state.
The VoIP function is configured for the application in advance, so that a buffer period exists when the application is converted from the running state to the non-running state, the application is automatically restarted and registers the timing task to the operating system by using the buffer period, the operating system can periodically wake up the application which is in the suspended state after being restarted according to the timing task, and the application is resident in the background.
With reference to the third aspect, in a first possible implementation manner of the third aspect, when the application is in the foreground state, the processor is further configured to:
when a predetermined operation is detected, converting the application from the foreground state to the suspended state;
waking up the application in the suspended state by a predetermined wake-up mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
When a user performs specific operation on the mobile terminal, so that the application is converted from a foreground state to a suspended state, the application is awakened from the suspended state through a data push awakening mode or a timing task awakening mode, and background resident of the application is realized.
With reference to the first possible implementation manner of the third aspect, in a second possible implementation manner of the third aspect, when the application is woken up by the data push wake-up manner, the processor is configured to:
and when receiving data pushed to the application by an application server, waking up the application in the suspended state.
When the application with the VoIP function is in the suspended state, the terminal takes over the connection between the application servers, and when the data sent by the application servers are received, the application in the suspended state is awakened, so that the application can process the received data in time.
With reference to the first possible implementation manner of the third aspect, in a third possible implementation manner of the third aspect, when the application is woken up by the timed task wake-up manner, the processor is configured to:
registering the timed task with the operating system in the process of starting the application;
the processor is further configured to:
and according to the timing task, periodically waking up the application in the suspended state.
In order to avoid that the application is killed or quitted by the operating system due to the fact that the application is in the suspended state for a long time, the application registers the timing task in the starting stage, when the application is in the suspended state, the operating system wakes up the application regularly according to the timing task, the application is prevented from being killed or quitted by the operating system, and therefore background resident of the application is achieved.
With reference to the third aspect, the first possible implementation manner of the third aspect, the second possible implementation manner of the third aspect, or the third possible implementation manner of the third aspect, in a fourth possible implementation manner of the third aspect, the application after waking up is transitioned back to the suspended state after maintaining the background state for the first duration.
The awakened application enters the suspended state again after maintaining the background state for a period of time, so that the application can run in the background, and the shortage of processing resources caused by the fact that the application occupies the background for a long time is avoided.
With reference to the first possible implementation manner of the third aspect, the second possible implementation manner of the third aspect, or the third possible implementation manner of the third aspect, in a fifth possible implementation manner of the third aspect, after the converting the application from the foreground state to the suspended state, the processor is further configured to:
receiving a background task application sent by the application in a process of converting from a foreground state to a background state, wherein the background task application is used for requesting the operating system to allow the application to maintain the background state for a second duration;
and when the second duration is over, converting the application from the background state to the suspended state.
And the application applies for the background running time of the second duration and actively stops code execution when the second duration is reached, so that the operating system can convert the application from the background state to the suspended state. The application can be prevented from being killed by an operating system due to exceeding the limit while acquiring the extra background running time, so that the application is ensured to be resident in the background.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below.
FIG. 1 is a diagram illustrating a transition relationship between a foreground state, a background state, a suspended state, and an un-running state of an application in an embodiment of the present invention;
fig. 2A is a schematic flowchart illustrating an application state transition method according to an embodiment of the present invention;
FIG. 2B is a diagram illustrating a transition relationship between different states in the application state transition method shown in FIG. 2A;
fig. 3A is a schematic flowchart illustrating another application state transition method according to an embodiment of the present invention;
fig. 3B is a flowchart illustrating a further application state transition method according to an embodiment of the present invention;
fig. 4A is a schematic diagram of message push implemented by using an APNS push service;
FIG. 4B is a diagram illustrating a message push implemented by a local push service;
fig. 5 is a block diagram illustrating an application state transition apparatus according to an embodiment of the present invention;
fig. 6 is a block diagram of another application state transition device provided in the embodiment of the present invention;
fig. 7 shows a schematic structural diagram of a mobile terminal according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
For convenience of understanding, terms referred to in the embodiments of the present invention are explained below.
1. Foreground state: indicating the state of the application running in the foreground of the operating system. In general, when a user starts an application in a system, the application is in a foreground state.
2. A background state: and indicating that the application is in a state of background and running of the operating system, and executing the application code in the background of the system by the application in the background state.
3. A suspended state: indicating that the application is in the background of the operating system but not executing code.
4. The non-operating state: indicating a state in which the application is not started or terminated by the system during execution.
5. VoIP background task interface: the iOS provides a background technology interface. And when the iOS device receives data sent to the application by the application server, the iOS awakens the application in the suspended state so as to process the received data.
6. Background task application interface: the iOS provides a background technology interface. An application using the interface can apply for a certain length of background running time to the iOS, and typically, the application applies for a maximum of 3 minutes of background running time by using the interface.
Referring to FIG. 1, a transition relationship between a foreground state, a background state, a suspended state, and an un-running state of an application is illustrated. For convenience of description, the operating system is taken as an iOS in this embodiment, and the present invention is not limited thereto.
When the user clicks the application icon, the iOS starts the application corresponding to the application icon, and correspondingly, the application is in the foreground state.
When the user performs a predetermined operation, such as pressing a Home key of the iOS device, the application in the foreground state transitions to the suspended state (transition 101 in fig. 1), and no more application code is executed; when the user clicks the application icon of the application again, the application is converted into the foreground state from the suspended state again.
For applications such as VoIP, in order to make the application still run in the operating system background, when the Home key of the iOS device is pressed, the application is switched from the foreground state to the background state (i.e., transition 102 in fig. 1); meanwhile, in order to avoid that the application is in a long-time background state, when the application maintains the background state for a certain time, the application is automatically switched from the background state to the suspended state (i.e. the switching 103 in fig. 1).
An application in the foreground state may crash and go to the non-running state (i.e., transition 104 in fig. 1) due to a code bug or the like; similarly, an application in the background state may also go to the non-running state (i.e., transition 105 in FIG. 1) when killed or exited by the iOS. After the application enters the non-running state, if the user does not manually click the application icon to restart the application, the application will remain in the non-running state, and the application cannot be resident in the background, and for some applications needing background push, the instantaneity of the push message will be affected.
In order to implement application background resident in an operating system, an embodiment of the present invention provides an application state transition method, by which an application can be automatically restarted in a background to implement background resident in the application, which is described below with an exemplary embodiment.
Referring to fig. 2A, a flowchart of an application state transition method according to an embodiment of the invention is shown. The present embodiment is described by taking as an example that the method is applied to an iOS-installed device, and the method includes:
When the engineering file of the iOS application is configured, the VoIP function is configured by using the VoIP background interface provided by the iOS, and the VoIP is started when the application is started.
And 204, when the application is determined to start to be converted from the running state to the non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state.
When the application for starting the VoIP is converted from the running state to the non-running state, there is a buffer period of a certain duration, for example, the application needs 2 to 3 seconds (which may be referred to as a buffer period) to be converted from the running state to the non-running state, and the operating system can automatically restart the application using the buffer period.
And step 208, periodically waking up the application in the suspended state according to the timing task, wherein the application after being woken up is in a background state.
And the iOS ensures that the application in the suspended state is awakened in the period indicated by the timing task according to the timing task registered by the application, so that the application enters a background state. And after the application entering the background state is maintained for a period of time, the application enters the suspended state again.
As shown in fig. 2B, on the basis of the state transition shown in fig. 1, the application is put into the suspended state (i.e., transition 106 in fig. 2B) by restarting it with a buffer period before the application is put into the non-running state; and periodically awakens the application in the suspended state (i.e., transition 107 in fig. 2B) according to the timing task registered during the restart process, thereby enabling the application to be resident in the background.
In summary, in the application state transition method provided in this embodiment, the application is restarted by using the buffer period before the application enters the non-running state from the running state, so that the application enters the suspended state, and the application in the suspended state is periodically awakened according to the timing task registered in the restart process; the problem that the application cannot reside in the background because the application is killed or quitted by the iOS and enters an unoperated state is solved; the effect of realizing application resident in the background by utilizing an automatic restart and timing wakeup mechanism is achieved.
When a user performs some operations to make an application enter a suspended state from a foreground state (for example, clicking a Home key), if the application is in the suspended state for a long time, the operating system will automatically kill or quit the application, so that the application cannot reside in the background. Based on the embodiment shown in fig. 2A, the application in the suspended state may be periodically woken up to be resident in the background by a timed wake-up mechanism, which is described below with an embodiment.
Referring to fig. 3A, a flow chart of another application state transition method according to an embodiment of the invention is shown. The present embodiment is described by taking as an example that the method is applied to an iOS-installed device, and the method includes:
When the engineering file of the iOS application is configured, the VoIP function is configured by using the VoIP background interface provided by the iOS, and the VoIP is started when the application is started. It should be noted that the application configured with the VoIP function is not limited to the VoIP-type application, and the application may also be an application having a message pushing function, such as a mail application.
The application runs in a foreground state after being started, and processes the data when receiving the data sent by the application server. For example, taking the application as a mail application as an example, when a user starts the mail application in the iOS device, the mail application is run in the foreground, and when the mail server pushes a mail to the mail application, the mail application in the foreground displays the received mail.
More applications are usually installed in the iOS device, and when a user switches different applications, the application currently in the foreground needs to be moved to the background; moreover, in order to avoid that a large number of applications run in the background and affect the processing performance of the iOS, the applications moved to the background need to be transferred to a suspended state. Therefore, when a predetermined operation is detected, such as a pressing operation of the Home key by the user, the application enters the suspended state from the foreground state.
The application in the suspended state does not run a code in the background and cannot realize real background resident, so the iOS needs to wake up the application in the suspended state to make the application enter the background state, thereby realizing real background resident.
In one possible embodiment, since the application has VoIP turned on, in the suspended state, the iOS will take over the connection between the application and the application server. When the iOS receives the data sent by the application server to the application, the iOS wakes up the application in the suspended state. And the awakened application maintains a background state of a first duration, runs the code in the background state and processes the received data, and when the first duration is reached, the application is converted into a suspended state again. For example, the first duration may be 10 seconds, i.e., after the application is woken up by the iOS, the background state is maintained for 10 seconds, and the suspended state is re-entered after 10 seconds. It should be noted that, in order to avoid frequent waking up of the application by the iOS, the iOS needs to limit the number of times of waking up the application by using the data push wake-up method in a unit time, for example, the number of times of waking up the application in 5 minutes may be set to be at most 15 times, and when the limit is exceeded, the iOS kills the application.
In another possible embodiment, the application registers a timing task with the iOS during the start-up phase, the timing task being used to instruct the iOS to periodically wake up the application in the suspended state. Correspondingly, the iOS periodically wakes up the application in the suspended state according to the timing task of the application registration. The awakened application maintains the background state of the first duration and is converted into the suspended state again when the first duration is reached. For example, the timing task period of the timing task may be set to 600 seconds, and the first duration may be 10 seconds, that is, the iOS ensures that the application in the suspended state is woken up once in 600 seconds, and the woken-up application maintains the background state for 10 seconds and then re-enters the suspended state. The application is awakened by adopting a timing awakening mode, so that the application can be effectively prevented from being killed or quitted by the iOS due to the fact that the application is in a suspended state for a long time.
It should be noted that the iOS may determine the time interval between two adjacent wakens according to the usage rate of a Central Processing Unit (CPU) or a memory, that is, the time interval between two adjacent wakens is smaller than the timing task period and is not a fixed value. For example, taking the timing task cycle of the timing task as 600 seconds as an example, when the usage rate of the CPU or the memory is greater than the threshold, the iOS may wake up the application again 580 seconds before the last wake-up; when the CPU or memory usage is less than a threshold, the iOS may wake the application again 500 seconds from the last wake.
Another point to be noted is that, in order to avoid frequent waking up of the application by the iOS, the iOS needs to limit the timing task period of the timing task, for example, the timing task period may be limited to at least 600 seconds, and if the timing task period of the registered timing task is greater than or equal to 600 seconds, the timing task is successfully registered; and if the timing task period of the registered timing task is less than 600 seconds, the timing task fails to be registered.
And step 304, when the application is determined to start to be converted from the running state to the non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state.
The reason for causing the application to enter the non-running state is various, for example, when the application in the foreground state crashes due to code defects, the application is converted into the non-running state from the foreground state; for another example, when an application in the background state is frequently woken up, the iOS kills or exits the application so that the application enters the bit-running state from the background state. It should be noted that the embodiment of the present invention does not discuss a case where the user manually exits the application to cause the application to enter the non-running state.
For the application that starts the VoIP, a buffer period of a certain duration may pass before the application is converted into the non-running state.
And in the restarting process, registering a timing task to the iOS, and indicating the iOS to periodically wake up the application in the suspended state. If the timing task period of the registered timing task reaches the preset time length, the registration is successful; if the timing task period of the registered timing task does not reach the preset time length, the registration fails, wherein the timing task period can be 600 seconds.
After the application successfully registers the timing task, the operating system periodically wakes up the application in the suspended state according to the timing task period set by the timing task. The awakened application maintains the background state of the first duration and is converted into the suspended state again when the first duration is reached.
In summary, in the application state transition method provided in this embodiment, the application is restarted by using the buffer period before the application enters the non-running state from the running state, so that the application enters the suspended state, and the application in the suspended state is periodically awakened according to the timing task registered in the restart process; the problem that the application cannot reside in the background because the application is killed or quitted by the iOS and enters an unoperated state is solved; the effect of realizing application resident in the background by utilizing an automatic restart and timing wakeup mechanism is achieved.
In the embodiment, by configuring the engineering file of the application in advance and setting the wakeup mechanism, when the application is in the suspended state, the iOS can wake up the application in a data push wakeup mode or a timing task wakeup mode; when the application enters the non-running state, the automatic restart of the application can be realized through an automatic restart mechanism, and the application is awakened into a background state by the iOS at regular time after the restart, so that the application background can be resident in the true sense.
On the basis of the embodiment shown in fig. 3A, when the iOS indicates that the application is converted from the foreground state to the suspended state, the application may apply for additional background running time through a background task application interface provided by the iOS, thereby further prolonging the time that the application is in the background state. As shown in fig. 3B, after the step 302, the following steps may be further included.
When the Home key of the iOS device is pressed, the application in the foreground state sends a background task application to the iOS through the background task application interface, and applies for maintaining the background state for a second duration, wherein the second duration may be 3 minutes.
Through the background task application mechanism, after the Home key of the iOS device is pressed, the application can not be directly converted into the suspended state from the foreground state, but can continue to maintain the background state for a period of time, execute the code in the background state and process the received data, and the timeliness of receiving and processing the data by the application can be improved.
It should be noted that, when the Home key is pressed, a mechanism of sending a background task application to the iOS needs to be configured in the engineering file of the application in advance.
And 308, converting the application from the background state to the suspended state when the second duration is over.
In order to avoid that the application is killed by the iOS due to exceeding of the background limit, the application maintains a background state and runs codes within a second duration after the Home key is pressed, the codes are automatically stopped running when the second duration is close to the end, and the iOS enables the application to enter a suspended state after detecting the codes of the application stopping running, so that the application is prevented from being killed or quitted by the iOS due to exceeding of the background limit. It should be noted that the application active stop operation code may be implemented by calling a corresponding interface provided by the iOS, which is not described herein again.
In the embodiment, in the process that the application enters the background state from the foreground state, the application applies for the extra background running time through the background task application interface, so that the time of the application in the background state is further prolonged, and the timeliness of receiving and processing data by the application can be improved for the application with higher instantaneity requirement.
The application state transition method provided by the foregoing embodiment may be used in an application with a message push requirement, and the application state transition method is schematically described below by taking an example in which the application state transition method is used in a mail application.
As shown in fig. 4A, when the mail application in the iOS is not configured in advance by the foregoing method, when the mail server 41 pushes a message to the mail application in the iOS device 42, the message needs to be sent to an Apple Push Notification Service (APNS) server 43, the APNS server 43 analyzes the device information of the iOS device carried in the message, and then forwards the message to the corresponding iOS device 42 and finally pushes the message to the mail application, obviously, the APNS server needs to be relied on when the APNS Push Service is used to receive the pushed message.
If the local push service is used to receive the message instead of the APNS push service, the mail application in the iOS device is required to reside in the background without depending on the APNS server, and the application background can be resident by using the application state conversion method provided by the above embodiment.
In the application project file configuration stage, when a developer configures an application project file for mail application, a VoIP function is started; in the application starting stage, the mail application registers a timing task to the iOS, and instructs the iOS to periodically wake up the mail application, so that the mail application in a suspended state for a long time is prevented from being killed by the iOS and then is withdrawn; in the foreground operation process, when a user presses a Home key, the mail application calls a background task application interface provided by the iOS to maintain an additional background state for 3 minutes (a second time length), and stops executing codes when the time is close to 3 minutes, and when the iOS detects that the application stops executing the codes, the application is converted into a suspended state; in the suspended state, because the mail application starts the VoIP function, the iOS takes over the connection between the mail application and the mail server, and wakes up the mail application to process the pushed message when receiving the message pushed by the mail server, so as to realize the background resident of the mail application.
When the mail application enters the non-running state from the foreground state or the background state, the mail application restarts the application by using the buffer period before entering the non-running state, and registers a timing task with the iOS when restarting. The restarted mail application is in a suspended state in the iOS background until the iOS wakes the mail application periodically according to a timing task and enters a background state, so that the background of the application is resident.
As shown in fig. 4B, the application state transition method provided by the foregoing embodiment may implement that the mail application is resident in the background, and the mail application may receive a message pushed by the mail server by using a local push service, that is, the mail server 41 may directly push a message to the mail application in the iOS device 42, so as to avoid relying on the APNS server.
Referring to fig. 5, a block diagram of an application state transition device according to an embodiment of the present invention is shown. The application state transition device can be implemented by software, hardware or a combination of the two as all or part of the mobile terminal. The application state transition means may include: a startup unit 510, a restart unit 520, a registration unit 530, and a wake-up unit 540.
A starting unit 510, configured to start an application, where the application configures a VoIP function through a VoIP background interface provided by an operating system;
a restart unit 520, configured to restart the application before the completion of the transition when it is determined that the application starts to transition from the running state to the non-running state, where the running state includes a foreground state or a background state;
a registering unit 530, configured to register a timing task with the operating system in the process of restarting the application, where the timing task is used to instruct the operating system to periodically wake up the application in the suspended state;
and the waking unit 540 is configured to periodically wake up the application in the suspended state according to the timing task, where the application after being woken up is in a background state.
In summary, the application state transition device provided in this embodiment restarts an application by using a buffer period before the application enters an un-running state from a running state, so that the application enters a suspended state, and periodically wakes up the application in the suspended state according to a timing task registered in the restart process; the problem that the application cannot reside in the background because the application is killed or quitted by the iOS and enters an unoperated state is solved; the effect of realizing application resident in the background by utilizing an automatic restart and timing wakeup mechanism is achieved.
Referring to fig. 6, a block diagram of another application state transition device according to an embodiment of the present invention is shown. The application state transition device can be implemented by software, hardware or a combination of the two as all or part of the mobile terminal. On the basis of fig. 5, the application state transition device may further include:
a transition unit 550 for transitioning the application from the foreground state to the suspended state when a predetermined operation is detected;
the waking unit 540 is further configured to wake up the application in the suspended state through a predetermined waking manner; the predetermined wake-up mode comprises at least one of a data push wake-up mode or a timed task wake-up mode.
In one possible embodiment, when an application is woken up by a data push wake up approach;
and a waking unit 540, configured to wake up the application in the suspended state when receiving the data pushed to the application by the application server.
In one possible embodiment, when an application is woken up by a timed task wake-up approach;
a starting unit 510, further configured to register a timing task with an operating system in the process of starting an application;
the waking unit 540 is further configured to periodically wake up the application in the suspended state according to the timing task.
In one possible implementation, the woken-up application maintains the background state for the first duration and then transitions to the suspended state again.
In one possible embodiment, the apparatus further comprises:
a receiving unit 560, configured to receive a background task application sent by the application in a process of converting from a foreground state to a background state, where the background task application is used to request the operating system to allow the application to maintain the background state for a second duration.
The converting unit 550 is further configured to convert the application from the background state to the suspended state when the second duration is over.
In summary, the application state transition device provided in this embodiment restarts an application by using a buffer period before the application enters an un-running state from a running state, so that the application enters a suspended state, and periodically wakes up the application in the suspended state according to a timing task registered in the restart process; the problem that the application cannot reside in the background because the application is killed or quitted by the iOS and enters an unoperated state is solved; the effect of realizing application resident in the background by utilizing an automatic restart and timing wakeup mechanism is achieved.
In the embodiment, by configuring the engineering file of the application in advance and setting the wakeup mechanism, when the application is in the suspended state, the iOS can wake up the application in a data push wakeup mode or a timing task wakeup mode; when the application enters the non-running state, the automatic restart of the application can be realized through an automatic restart mechanism, and the application is awakened into a background state by the iOS at regular time after the restart, so that the application background can be resident in the true sense.
In the embodiment, in the process that the application enters the background state from the foreground state, the application applies for the extra background running time through the background task application interface, so that the time of the application in the background state is further prolonged, and the timeliness of receiving and processing data by the application can be improved for the application with higher instantaneity requirement.
Referring to fig. 7, a schematic structural diagram of a mobile terminal 700 according to an embodiment of the invention is shown. The mobile terminal 700 may be a smartphone, a tablet pc, an e-book reader or an MP4 (english: Moving picture experts Group Audio Layer IV, abbreviated as MP4) player, etc. with iOS installed.
The mobile terminal 700 may include: processor 710, memory 720, and display 730. Those skilled in the art will appreciate that the architecture of the mobile terminal 700 shown in fig. 7 is not intended to be limiting of the mobile terminal and may include more or fewer components than shown, or some components in combination, or a different arrangement of components. Wherein:
the processor 710 is a control center of the mobile terminal 700, connects various parts of the entire mobile terminal using various interfaces and lines, and performs various functions of the mobile terminal 700 and processes data by operating or executing software programs and/or modules stored in the memory 720 and calling data stored in the memory 720, thereby performing overall control of the mobile terminal 700. Optionally, processor 710 may include one or more processing cores; optionally, the processor 710 may integrate an application processor, a modem processor, and a coprocessor, wherein the application processor mainly processes an operating system, a user interface, an application program, and the like, the modem processor mainly processes wireless communication, and the coprocessor is used for processing sensor data or touch screen data, for example, the coprocessor includes a touch integrated circuit. It will be appreciated that the modem processor and co-processor described above may also be present in separate processors rather than being integrated into the processor 710.
Memory 720 may be used to store software programs and modules. The processor 710 executes various functional applications and data processing by executing software programs and modules stored in the memory 720. The memory 720 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system 721, a registration unit 722, a wakeup unit 723, and at least one application 724; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the mobile terminal 700, and the like. In addition, the Memory 720 may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as a Static Random Access Memory (SRAM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), an Erasable Programmable Read-Only Memory (EPROM), a Programmable Read-Only Memory (PROM), a Read-Only Memory (ROM), a magnetic Memory, a flash Memory, a magnetic disk, or an optical disk. Accordingly, memory 720 may also include a memory controller to provide processor 710 access to memory 720.
The display screen 730 is a display component having a display function, and the display screen 730 can be a touch screen or a non-touch screen.
The mobile terminal 700 further includes a power supply (not shown) for supplying power to various components, and preferably, the power supply is logically connected to the processor 710 through a power management system, so that functions of managing charging, discharging, and power consumption are implemented through the power management system. The power supply may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and the like.
Although not shown, the mobile terminal 700 may further include a camera, a bluetooth module, etc., which will not be described herein.
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.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.
Claims (18)
1. An application state transition method, used in a mobile terminal, where an operating system is installed in the mobile terminal and at least one application is installed in the operating system, the method comprising:
starting the application, wherein the application configures a VoIP function through a VoIP background interface of the network voice call provided by the operating system;
when the application is determined to start to be converted from a running state to a non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state;
registering a timing task with the operating system in the process of restarting the application, wherein the timing task is used for indicating the operating system to periodically wake up the application in a suspended state;
if the timing task period of the timing task reaches the preset time length, the registration is successful;
if the registration is successful, according to the timing task, the application in the suspended state is awakened periodically, and the awakened application is in the background state.
2. The method of claim 1, wherein when the application is in the foreground state, the method further comprises:
when a predetermined operation is detected, converting the application from the foreground state to the suspended state;
waking up the application in the suspended state by a predetermined wake-up mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
3. The method according to claim 2, wherein when waking up the application by the data push wake pattern, the waking up the application in the suspended state by a predetermined wake pattern comprises:
and when receiving data pushed to the application by an application server, waking up the application in the suspended state.
4. The method of claim 2, wherein when the application is woken up by the timed task wake up mode, the launching the application comprises:
registering the timed task with the operating system in the process of starting the application;
the waking up the application in the suspended state by a predetermined waking up mode includes:
and according to the timing task, periodically waking up the application in the suspended state.
5. The method according to any one of claims 1 to 4, wherein the application after waking up is transitioned to the suspended state again after maintaining the background state for the first duration.
6. The method of any of claims 2 to 4, further comprising:
receiving a background task application sent by the application in a process of converting from a foreground state to a background state, wherein the background task application is used for requesting the operating system to allow the application to maintain the background state for a second duration;
and when the second duration is over, converting the application from the background state to the suspended state.
7. An application state conversion device, wherein the device is used in a mobile terminal, an operating system is installed in the mobile terminal, and at least one application is installed in the operating system, the device comprising:
the starting unit is used for starting the application, and the application configures a VoIP function through a VoIP background interface of the network voice call provided by the operating system;
the restarting unit is used for restarting the application before the conversion is completed when the application is determined to start to convert from the running state to the non-running state, wherein the running state comprises a foreground state or a background state;
a registering unit, configured to register a timing task with the operating system in a process of restarting the application, where the timing task is used to instruct the operating system to periodically wake up the application in a suspended state; if the timing task period of the timing task reaches the preset time length, the registration is successful;
and the awakening unit is used for periodically awakening the application in the suspended state according to the timing task if the registration is successful, and the awakened application is in the background state.
8. The apparatus of claim 7, wherein the apparatus comprises:
a conversion unit configured to convert the application from the foreground state to the suspended state when a predetermined operation is detected;
the awakening unit is further used for awakening the application in the suspended state through a preset awakening mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
9. The apparatus according to claim 8, wherein when the application is woken up by the data push wake-up manner, the wake-up unit is configured to wake up the application in the suspended state when receiving data pushed to the application by an application server.
10. The apparatus of claim 8, wherein when the application is woken up by the timed task wake up mode; the starting unit is further used for registering the timing task to the operating system in the process of starting the application;
the awakening unit is further configured to periodically awaken the application in the suspended state according to the timing task.
11. The apparatus according to any one of claims 7 to 10, wherein the application after waking up is transitioned to the suspended state again after maintaining the background state for the first duration.
12. The apparatus of any one of claims 8 to 10, further comprising:
a receiving unit, configured to receive a background task application sent by the application in a process of converting from a foreground state to a background state, where the background task application is used to request the operating system to allow the application to maintain the background state for a second duration;
the conversion unit is further configured to convert the application from the background state to the suspended state when the second duration is over.
13. A mobile terminal, characterized in that the mobile terminal comprises: a processor and a memory coupled to the processor, wherein the memory is configured to store one or more instructions configured to be executed by the processor, the mobile terminal is installed with an operating system, and the processor is configured to:
starting the application, wherein the application configures a VoIP function through a VoIP background interface of the network voice call provided by the operating system;
when the application is determined to start to be converted from a running state to a non-running state, restarting the application before the conversion is completed, wherein the running state comprises a foreground state or a background state;
registering a timing task with the operating system in the process of restarting the application, wherein the timing task is used for indicating the operating system to periodically wake up the application in a suspended state;
if the timing task period of the timing task reaches the preset time length, the registration is successful;
if the registration is successful, according to the timing task, the application in the suspended state is awakened periodically, and the awakened application is in the background state.
14. The mobile terminal of claim 13, wherein when the application is in the foreground state, the processor is further configured to:
when a predetermined operation is detected, converting the application from the foreground state to the suspended state;
waking up the application in the suspended state by a predetermined wake-up mode; the preset awakening mode comprises at least one of a data push awakening mode or a timing task awakening mode.
15. The mobile terminal of claim 14, wherein when the application is woken up by the data push wake up mode, the processor is configured to:
and when receiving data pushed to the application by an application server, waking up the application in the suspended state.
16. The mobile terminal of claim 14, wherein when the application is woken up by the timed task wake-up mode, the processor is configured to:
registering the timed task with the operating system in the process of starting the application;
the processor is further configured to:
and according to the timing task, periodically waking up the application in the suspended state.
17. The mobile terminal according to any of claims 13 to 16, wherein the application after waking up is transitioned to the suspended state again after maintaining the background state for the first duration.
18. The mobile terminal of any of claims 14 to 16, wherein the processor is further configured to:
receiving a background task application sent by the application in a process of converting from a foreground state to a background state, wherein the background task application is used for requesting the operating system to allow the application to maintain the background state for a second duration;
and when the second duration is over, converting the application from the background state to the suspended state.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610167883.4A CN107231386B (en) | 2016-03-23 | 2016-03-23 | Application state conversion method and device and mobile terminal |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610167883.4A CN107231386B (en) | 2016-03-23 | 2016-03-23 | Application state conversion method and device and mobile terminal |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107231386A CN107231386A (en) | 2017-10-03 |
CN107231386B true CN107231386B (en) | 2020-07-07 |
Family
ID=59931587
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610167883.4A Active CN107231386B (en) | 2016-03-23 | 2016-03-23 | Application state conversion method and device and mobile terminal |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107231386B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108062190B (en) * | 2017-12-28 | 2020-06-09 | 维沃移动通信有限公司 | Application running state control method and mobile terminal |
CN108052258B (en) * | 2017-12-28 | 2020-02-11 | 维沃移动通信有限公司 | Terminal task processing method, task processing device and mobile terminal |
CN109708634A (en) * | 2018-12-12 | 2019-05-03 | 平安科技(深圳)有限公司 | Judge automatically method, apparatus, storage medium and the electronic equipment of driving behavior |
CN110650259B (en) * | 2019-08-26 | 2021-08-17 | 中移(杭州)信息技术有限公司 | Call request response method, device, server, terminal and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103369641A (en) * | 2012-04-01 | 2013-10-23 | 北京百度网讯科技有限公司 | Method and device for receiving pushed messages by mobile terminal, and mobile terminal |
CN103491175A (en) * | 2013-09-25 | 2014-01-01 | 北京网秦天下科技有限公司 | Method and terminal for application program management |
CN104426893A (en) * | 2013-09-09 | 2015-03-18 | ***通信集团公司 | Method, device and system for awakening mobile terminal |
WO2015188761A1 (en) * | 2014-06-12 | 2015-12-17 | Tencent Technology (Shenzhen) Company Limited | Traffic acquiring method and apparatus based on operating system |
-
2016
- 2016-03-23 CN CN201610167883.4A patent/CN107231386B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103369641A (en) * | 2012-04-01 | 2013-10-23 | 北京百度网讯科技有限公司 | Method and device for receiving pushed messages by mobile terminal, and mobile terminal |
CN104426893A (en) * | 2013-09-09 | 2015-03-18 | ***通信集团公司 | Method, device and system for awakening mobile terminal |
CN103491175A (en) * | 2013-09-25 | 2014-01-01 | 北京网秦天下科技有限公司 | Method and terminal for application program management |
WO2015188761A1 (en) * | 2014-06-12 | 2015-12-17 | Tencent Technology (Shenzhen) Company Limited | Traffic acquiring method and apparatus based on operating system |
Also Published As
Publication number | Publication date |
---|---|
CN107231386A (en) | 2017-10-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107231386B (en) | Application state conversion method and device and mobile terminal | |
KR101799418B1 (en) | Application heartbeat period adjusting method and apparatus, and terminal | |
CN102622079B (en) | Sleep method, wakening method and mobile terminal device | |
JP6298585B2 (en) | Electronic device, electronic device wake-up method and apparatus | |
US9319993B1 (en) | Injecting active periods into scheduled inactive periods | |
WO2016165078A1 (en) | Method and terminal for controlling application | |
CN105373207B (en) | A kind of idle method of wireless communication terminal | |
CN108040292B (en) | Television standby starting method, television and computer readable storage medium | |
CN106815065B (en) | Background application awakening method and device and electronic equipment | |
WO2010139169A1 (en) | Electricity-saving method and device for terminal | |
WO2015077961A1 (en) | Method for sending heartbeat message and mobile terminal | |
CN104156223A (en) | Application program control method and device for mobile terminal | |
WO2018010596A1 (en) | Mode switching method and device | |
WO2015172283A1 (en) | Method, device and mobile terminal for reducing power consumption | |
US10338936B2 (en) | Method for controlling schedule of executing application in terminal device and terminal device implementing the method | |
CN107436672B (en) | Application processing method and terminal | |
CN105824391A (en) | Timer awakening control method and electronic equipment | |
JP5504247B2 (en) | Electronic device and timer time setting method | |
WO2014176893A1 (en) | Method and device for powering off mobile terminal | |
CN114327606A (en) | Configuration management method and device, electronic equipment and computer readable storage medium | |
CN110543333B (en) | Sleep processing method and device for processor, mobile terminal and storage medium | |
JPWO2008084541A1 (en) | Reception device and activation control method for reception device | |
CN117319376A (en) | File downloading control method and device, electronic equipment and storage medium | |
WO2018098901A1 (en) | Processing method and device for terminal service | |
TWI407765B (en) | Mobile device, power saving method and computer executable medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |