Android Learning Series (7)-App message push mechanism

Source: Internet
Author: User

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" />
3 <! -- Or -->
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 {
02   
03     // Obtain the message thread
04     private MessageThread messageThread = null;
05   
06     // Click to View Details
07     private Intent messageIntent = null;
08     private PendingIntent messagePendingIntent = null;
09   
10     // Notification bar message
11     private int messageNotificationID = 1000;
12     private Notification messageNotification =
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.