These days I have been wondering how to implement a set of push functions on the Android device. I also have a lot of information on Google. It seems that there are no more than the following three solutions (which are reproduced below ):
1) round robin: the application should be connected to the server in stages and check whether new messages arrive. You must implement communication with the server, 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) SMS: On the Android platform, you can intercept SMS messages and parse the message content to understand the server's intention. This is a good idea. I have seen applications that adopt this solution. The advantage of this solution is that it can achieve full real-time operations. However, the problem is that the cost of this solution is relatively high, and it is difficult to find a free short message sending gateway. For the implementation of this solution, refer to the following link: https://labs.ericsson.com/apis/mobile-java-push /.
3) 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.
- Poll?The name obviusly tells you that it's really not even push. the idea here is to periodically poll the server for new messages from a background local or remote service. the more often you poll the closer you get to the real-time push.
Advantages: easy to implement. no cost solutiondisadvantages: Obviously, you will never be actually real-time. if you polling interval is 30 min, you can get a message that is 29 minutes and 59 seconds late. moreover, polling more often than every 15-30 min will kill your battery pretty quick: https://labs.ericsson.com/apis/mobile-java-push/blog/save-device-battery-mobile-java-push
- SMSAndroid allows you to intercept SMS messages. your server sends a specially encoded SMS to your phone, whenever there is something new. your app intercepts all messages, looks for the ones from the server, then pops up a notification.
Advantages: easy to implement. fully real-time updates. known drop-in solutions exist such as one provided by Ericsson labs: https://labs.ericsson.com/apis/mobile-java-push/disadvantages: can be costly to you and the user. there are only a few services that allow you send around free SMS and even those are often limited to North America. if you want to have a reliable SMS-based service that is available worldwide, you will likely need to pay. similar goes for the users. not everyone has an SMS plan and you don't want your users getting charged by 3rd party for using your app.
- Persistent TCP/IPThe phone initiates a long-lived mostly idle TCP/IP connection with the server and maintains it by occasionally sending keepalive messages. whenever there is something new on the server, it sends a messages to the phone over the TCP connection.
Advantages: fully real-time updates.
Disadvantages: Hard to implement a reliable service on both the phone and the server side. the Android OS is known to be able to kill services when it's running low on memory, so your communications service can easily disappear. what happens when your phone goes to sleep? Some people complain about battery life issues related to maintaining an active connection.
Here are two well-spoken websites:
Http://tokudu.com/2010/how-to-implement-push-notifications-for-android/
Http://blog.csdn.net/joshua_yu/article/details/6563587
Of course, my first choice is to try c2dm. After registering the account for the c2dm service, Google's "ac2dm invitation" email says it is still in the trial, in addition, we need to achieve the product needs a stable environment, so try so far, it will give up halfway, interested can continue: http://code.google.com/intl/zh-CN/android/c2dm/#intro
Then, I started to use openfire + smack to build a push platform, use openfire as the PUSH Service, and then borrow the anroidpn open-source Engineering Code (with some modifications ), it can push information from the server to the android client. For this set of solutions, I did not do a concurrency test (here mentioned: http://wenku.baidu.com/view/85cfcd5f312b3169a451a41f.html) as well as a power consumption test, so I can only say that this is feasible and easy to implement.
In the end, there is no clear answer to which method we should choose, but it is not far from that ..