ANDROID Response Notification Event

Source: Internet
Author: User

Two cases

The first case is:

Click notification--> to enter secactivity ---back--- exit the app

Pendingintent contentintent = pendingintent.getactivity (context, 0,  intent, pendingintent.flag_cancel_current);  

Second case:

Click notification--> to enter secactivity ---- back to mainactivity -->back and exit the app

Need to add intent array, here is two units, so first Open is secactivity (intent[1]),

You need to set properties on the specified activity in manifest

<android:name= ". Secactivityl"        android:launchmode= " Singletask "        android:taskaffinity=" "        android:excludefromrecents  = "true"></activity>

Pendingintent provides a static method Getactivities, which allows you to set a intent array to specify a series of activity.

intent[] Makeintentstack (context context) {    new intent[2];    intents[0] = intent.makerestartactivitytask (new componentname (context, Com.example.notificationtest.MainActivity. class ));    intents[New Intent (context,  com.example.notificationtest.SubActivity.  Class);     return intents;}

One of the things to note is the Intent.makerestartactivitytask method, which is used to create the activity stack's root activity

Next, create and display the notification:

voidshownotification (Intent Intent) {Notification Notification=NewNotification (R.drawable.status_icon,Title at the top of the message Bar, System.currenttimemillis ()); Pendingintent contentintent=Pendingintent.getactivities ( This,            0, Makeintentstack ( This), pendingintent.flag_cancel_current); Notification.setlatesteventinfo ( This,             "Drop-down Message Bar title",            "Message Content", contentintent); Notification.flags|=Notification.default_all; Mnm.notify (1, notification);}

ANDROID Response Notification Event

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.