Disclosure of Invention
Embodiments of the present invention provide a method and an apparatus for processing an online push message, which overcome the above problems or at least partially solve the above problems.
On one hand, the embodiment of the invention provides a method for processing an online push message, which comprises the following steps:
s1, writing the online push message received by the first process into an SQLite database, and obtaining a query handle corresponding to the online push message;
s2, transferring the query handle from the first process to a second process;
s3, acquiring the online push message from the SQLite database based on the query handle received by the second process, and processing the online push message.
Wherein, before step S1, the method further includes:
setting the service priority of the push service in the first process to be the highest level.
Wherein, step S2 specifically includes:
if the second process is judged to be in the foreground, creating a first notification based on the online push message, wherein the query handle is encapsulated in the first notification;
passing the query handle from the first process to a second process when the first notification is clicked.
Wherein, step S2 specifically includes:
if the second process is judged to be in the background, a message Intent containing the query handle is created;
utilizing the message Intent to start an Activity component in the second process;
and extracting the query handle from the message Intent by using the Activity component in the second process.
Wherein, step S3 specifically includes:
and acquiring the online push message in the SQLite database based on the query handle received by the second process, and sending the online push message to a UI thread in the second process to complete the processing of the online push message.
In step S3, the processing the online push message further includes:
and if the second process is judged to be in the foreground, the on-line push message is analyzed by the UI thread, and the processing of the on-line push message is completed.
In step S3, the processing the online push message further includes:
and if the second process is judged to be in the background, establishing a second notification by using the UI thread, and when the second notification is clicked, analyzing the online push message by using the UI thread to complete the processing of the online push message.
In another aspect, an embodiment of the present invention provides an apparatus for processing an online push message, where the apparatus includes:
the writing module is used for writing the online push message received by the first process into the SQLite database and obtaining a query handle corresponding to the online push message;
a transfer module to transfer the query handle from the first process to a second process;
and the processing module is used for acquiring the online push message from the SQLite database based on the query handle received by the second process and processing the online push message.
In yet another aspect, the present invention provides a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, cause the computer to perform the processing method described above.
In yet another aspect, the present invention provides a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform the above-described processing method.
According to the method and the device for processing the online push message, the online push message is written into the SQLite database, the query handle is adopted to replace the online push message to be transmitted between the background process and the main process, and the main process queries the corresponding online push message in the SQLite database according to the obtained query handle and then analyzes and consumes the online push message, so that the processing of the online push message is completed. The query handle can not be lost when being transmitted between the background process and the main process, so that the problem of message loss when the online push message is transmitted between the background process and the main process is solved, the success rate of online push is improved, and the online push message is pushed more efficiently and timely.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some embodiments, but not all embodiments, of the present invention. 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.
Before describing in detail the aspects of the embodiments of the present invention, the following terms are explained in order to facilitate better understanding of the aspects of the embodiments of the present invention
Push (Push): the method refers to a new technology for reducing information overload by periodically transmitting information required by a user on the internet through a certain technical standard or protocol.
Socket: two programs on the network realize data exchange through a bidirectional communication connection, one end of the connection is called a Socket, the Socket is essentially A Programming Interface (API), and for encapsulation of TCP/IP, the TCP/IP also provides an interface which can be used by programmers for network development, and the interface is the Socket programming interface.
Long Connection (Persistent Connection): it means that a plurality of data packets can be continuously transmitted on one connection, and if no data packet is transmitted during the connection holding period, a link detection packet needs to be transmitted by two parties.
Process (Process): the program in the computer is related to one running activity on a certain data set, and is a basic unit for resource allocation and scheduling of the system, and the process is also a basic execution entity of the program.
Main Process (Main Process): the process which is directly interacted with the user and is visible in the foreground is pointed, the priority is higher, and the process is not easy to kill.
Background Process (B-Process): the process runs after the user process in a silent mode for a long time and the user can not interact directly, and the priority is low and the process is easy to kill;
thread (Thread): sometimes referred to as Lightweight Process (LWP), is the smallest unit of program execution flow. A standard thread consists of a thread ID, a current instruction Pointer (PC), a register set, and a stack.
Main Thread (Main Thread): the method is also called as a UI thread, and refers to a main thread of an application runtime in an android system, and the main thread is responsible for distributing events (including drawing events) to a UI component, and the thread cannot perform time-consuming operations (network requests and database operations), otherwise ANR exceptions are easily caused.
Service (Service): one of the four major components of the android system, the Service is a system component which does not allow the user to directly interact with the Service, and the Service runs in the background for a long time, for example, a music player plays music and is in Service.
Intent service (intservice): one special type of service, the intent service, is typically used to perform time consuming operations, where a thread pool is maintained and the service book automatically stops servicing after the time consuming operations have been performed.
Intent: the method can be used not only between application programs, but also for interaction between an Activity component and a Service component inside the application programs, and the Intent can be understood as a medium for communication between different components to specially provide related information for the components to call each other.
A Handler: and mainly receiving data sent by the sub-thread, and updating the UI by matching the data with the main thread.
Online Push (Online Push, ON-Push): when the application process is in an active state, the application background push service process and the push server maintain messages received in a long connection process.
Notification (Notification): one type of message presentation for android systems is typically presented in a panel format with title and keyword content at the top notification bar.
Online Notification (ON-Notification): one type of notification, which is created and exposed by the application itself.
Activity component: one of the four major components of the android system is a basic component unit which is directly interacted with a user, and data communication in a process or between processes can be achieved.
Broadcast (Broadcast): one of the four major components of the android system, broadcast is generally used to perform communication between threads inside application processes, or between different processes.
Content Provider component: one of the four major components of the android system is generally used for data transfer across processes.
Fig. 1 is a processing method for an online push message according to an embodiment of the present invention, as shown in fig. 1, the method includes: s1, writing the online push message received by the first process into an SQLite database, and obtaining a query handle corresponding to the online push message; s2, transferring the query handle from the first process to a second process; s3, acquiring the online push message from the SQLite database based on the query handle received by the second process, and processing the online push message.
The first Process may be a background Process, which is used as a Push service Process (Push Process) and is responsible for receiving and routing a message from a Push server. The second Process may be responsible for the processing of messages for a Main Process (Main Process).
Specifically, the background process starts a Push Service (Push Service), and receives an online Push message pushed by the Push server. After receiving the online push message, the background process converts the online push message into a JSON (JSON object tagging) format, writes the online push message into an SQLite database by using an SQLite, and obtains a query handle corresponding to the online push message and fed back by the SQLite. In order to ensure the high efficiency and freshness of online message pushing, the SQLite database is stored in an application cache directory, and the SQLite database is emptied after the cache directory is cleared. And the background process transmits the query handle to the main process, and the main process queries according to the query handle to obtain the corresponding online push message. The main process analyzes and consumes the received online push message to complete the processing of the online push message.
According to the method for processing the online push message in the android system, provided by the embodiment of the invention, the online push message is written into the SQLite database, the query handle is adopted to replace the online push message to be transmitted between the background process and the main process, and the main process queries the corresponding online push message in the SQLite database according to the obtained query handle and then analyzes and consumes the online push message, so that the processing of the online push message is completed. The query handle can not be lost when being transmitted between the background process and the main process, so that the problem of message loss when the online push message is directly transmitted between the background process and the main process is solved, the success rate of online push is improved, and the online push message is more efficiently and timely pushed.
In the above embodiment, before step S1, the method further includes:
setting the service priority of the push service in the first process to be the highest level.
Specifically, the push service runs in the first process for a long time, the service priority of the push service is set to be the highest level, meanwhile, the push service establishes long connection with the push server by using a Socket communication means, and the first process preferentially starts the push service when the application is initialized, so that the timeliness of message delivery of the push server is ensured.
In the above embodiment, step S2 specifically includes:
if the second process is judged to be in the foreground, creating a first notification based on the online push message, and encapsulating the query handle in the first notification;
passing the query handle from the first process to a second process when the first notification is clicked.
Specifically, after the first process finishes writing the online push message into the SQLite database, whether the second process is in the foreground is judged, and the fact that the second process is in the foreground indicates that an interface corresponding to the App of the second process is visible on the terminal. And if the first process judges that the second process is in the foreground, the first process creates a first notification according to the title and the content of the online push message, encapsulates the query handle in the first notification, and finally displays the first notification in a notification bar. And when the user clicks the first notification, the second process acquires the query handle in the first notification and stores the query handle in the memory at the application level.
In the above embodiment, step S2 specifically includes:
if the second process is judged to be in the background, a message Intent containing the query handle is created;
utilizing the message Intent to start an Activity component in the second process;
and extracting the query handle from the message Intent by using the Activity component in the second process.
Specifically, after the first process completes writing the online push message into the SQL database, it is determined whether the second process is in the foreground. And if the first process judges that the second process is in the background, the second process creates a message Intent, and the message Intent contains the query handle. And the second process starts the transparent Activity component in the second process through the message Intent, then the transparent Activity component in the second process receives the message Intent and extracts the query handle in the message Intent, the second process stores the query handle in the memory at the application level, and finally the transparent Activity component in the second process is rapidly destroyed after the work is completed.
In the above embodiment, step S3 specifically includes:
and acquiring the online push message in the SQLite database based on the query handle received by the second process, and sending the online push message to a UI thread in the second process to complete the processing of the online push message.
Specifically, after the second process stores the query handle to the application level memory, the second process starts an intention service. And then, the intention service uses a Content Provider component to query the corresponding online push message in the cache directory according to the query handle. And finally, the intention service sends the online push message to a UI thread in a second process by using a Handler. And after the UI thread successfully receives the online push message, the intention service immediately suspends the operation and waits for the arrival of the next online push message.
In the above embodiment, the processing the online push message in step S3 further includes:
and if the second process is judged to be in the foreground, the on-line push message is analyzed by the UI thread, and the processing of the on-line push message is completed.
Specifically, when the second process is in the foreground, the UI thread directly parses the received online push message and extracts the valid field of the online push message, thereby completing the processing of the online push message.
In the above embodiment, the processing the online push message in step S3 further includes:
and if the second process is judged to be in the background, establishing a second notification by using the UI thread, and when the second notification is clicked, analyzing the online push message by using the UI thread to complete the processing of the online push message.
Specifically, when the second process is in the background, the UI creates a second notification according to the title and the content of the received online push message, and displays the second notification in a notification bar. And when the user clicks the second notification, the UI thread analyzes the online push message in an internal broadcast mode to complete the processing of the online push message. The process can enable the second process to be switched from the background to the foreground, and the activity rate of the App is improved.
Fig. 2 is a block diagram of a structure of an apparatus for processing an online push message according to an embodiment of the present invention, and as shown in fig. 2, the apparatus includes: a write module 1, a transfer module 2 and a processing module 3. Wherein:
the writing module 1 is configured to write an online push message received by a first process into an SQLite database, and obtain a query handle corresponding to the online push message. The transfer module 2 is configured to transfer the query handle from the first process to a second process. The processing module 3 acquires the online push message from the SQLite database based on the query handle received by the second process, and processes the online push message.
The first Process may be a background Process, which is used as a Push service Process (Push Process) and is responsible for receiving and routing a message from a Push server. The second Process may be responsible for the processing of messages for a Main Process (Main Process).
Specifically, the background process starts a Push Service (Push Service), and receives an online Push message pushed by the Push server. After receiving the online push message, the background process converts the online push message into a JSON (JSON object tagging) format, writes the online push message into an SQLite database by using an SQLite, and obtains a query handle corresponding to the online push message and fed back by the SQLite. In order to ensure the high efficiency and freshness of online message pushing, the SQLite database is stored in an application cache directory, and the SQLite database is emptied after the cache directory is cleared. And the background process transmits the query handle to the main process, and the main process queries according to the query handle to obtain the corresponding online push message. The main process analyzes and consumes the received online push message to complete the processing of the online push message.
According to the processing device for the online push message in the android system, the online push message is written into the SQLite database through the writing module, the transmission module adopts the query handle to replace the online push message to transmit between the background process and the main process, the processing module queries the corresponding online push message in the SQLite database according to the obtained query handle, and then analyzes and consumes the online push message, so that the processing of the online push message is completed. The query handle can not be lost when being transmitted between the background process and the main process, so that the problem of message loss when the online push message is transmitted between the background process and the main process is solved, the success rate of online push is improved, and the online push message is pushed more efficiently and timely.
Embodiments of the present invention provide a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, which when executed by a computer, enable the computer to perform the methods provided by the above-mentioned method embodiments, for example, including: writing an online push message received by a first process into an SQLite database, and obtaining a query handle corresponding to the online push message; passing the query handle from the first process to a second process; and acquiring the online push message in the SQLite database based on the query handle received by the second process, and processing the online push message.
Embodiments of the present invention provide a non-transitory computer-readable storage medium, which stores computer instructions, where the computer instructions cause the computer to perform the methods provided by the above method embodiments, for example, the methods include: writing an online push message received by a first process into an SQLite database, and obtaining a query handle corresponding to the online push message; passing the query handle from the first process to a second process; and acquiring the online push message in the SQLite database based on the query handle received by the second process, and processing the online push message.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.