Android provides several common methods to push and receive messages:
1. Round Robin: ApplicationProgramYou should establish connections with the server in stages and check whether new messages arrive. You must implement communication with the server yourself, such as Message Queuing. In addition, you also need to consider the polling frequency. If it is too slow, it may lead to delay of some messages. If it is too fast, it will consume a lot of network bandwidth and battery.
2. persistent connection: this solution can solve the performance problem caused by polling, but it will still consume the cell phone's battery. The push service of apple works well because each mobile phone only maintains a connection with the server. In fact, c2dm works like this. However, this solution also has shortcomings, that is, it is difficult for us to implement a reliable service on the mobile phone. The Android operating system allows you to kill system services with low memory, so your notification service may be killed by the operating system.
In comparison, the 2nd types are the most feasible.Write System services or boot functions for the software; orIf the system resources are low, you can restart the service in the ondestroy () method after the service is shut down to achieve persistent connection.
There are currently some ready-made frameworks, such as androidpn (Android push notification), See http://blog.csdn.net/way_ping_li/article/details/7948269