Some people say that programmers are quiet, but I don't fully agree that the noise of programmers is hidden behind the code and behind the program.
This article is a must-have knowledge for android Developers. It is specially compiled and summarized for everyone. It is not perfect but useful.
1. Message push mechanism
The server needs to be changed from passive to active, notifying the customer of information that the developer deems important, whether or not the application is running or disabled.
I thought of one sentence: Dont call me, I will call you!
Today, a dialog box pops up in the lower right corner of QQ: "Obama announces that bin Laden has crashed.
If you are smart, you will be smart. If you like it, you will hate it.
2. Independent Processes
No matter whether the program is running or not, we must be able to notify the customer that we need an independent process Background Service.
We need a background service for an independent process.
In AndroidManifest. when registering a Service in xml, there is an android: process attribute, if this attribute is ". ", a global independent process is started for this service. If it starts with": ", an independent process private to this application is started for this service. For example, we have created an Application and the main process com. cnblogs. tianxia:
1 |
<! -- An independent process of com. cnblogs. tianxia. message will be created below --> |
2 |
< service android:name = ".service.MessageService" android:label = "Message push" android:process = ".message" /> |
4 |
<! -- A private com. cnblogs. tianxia: independent process of message will be created below --> |
5 |
< service android:name = ".service.MessageService" android:label = "Message push" android:process = ":message" /> |
We do not need to establish a global one. This article selects the second solution to create an independent process private to the current application.
3. Notify users and click to view
01 |
public class MessageService extends Service { |
03 |
// Obtain the message thread |
04 |
private MessageThread messageThread = null ; |
06 |
// Click to View Details |
07 |
private Intent messageIntent = null ; |
08 |
private PendingIntent messagePendingIntent = null ; |
10 |
// Notification bar message |
11 |
private int messageNotificationID = 1000 ; |
12 |
private Notification messageNotification = |