Android Learning Notification

Source: Internet
Author: User

1 write a base class activity so that other inheritance can be displayed to know which activity2  Public classBaseactivityextendsActivity {3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         //TODO auto-generated Method Stub6         Super. OnCreate (savedinstancestate);7LOG.D ("Baseactivity", GetClass (). Getsimplename ());8     }9 }Ten  One  Public classMainactivityextendsBaseactivityImplementsonclicklistener{ A     PrivateButton sendbtn; - @Override -     protected voidonCreate (Bundle savedinstancestate) { the         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -sendbtn=(Button) Findviewbyid (r.id.send_notice); -Sendbtn.setonclicklistener ( This); +          -     } +  A @Override at      Public BooleanOncreateoptionsmenu (Menu menu) { -         //inflate the menu; This adds items to the action bar if it is present. - getmenuinflater (). Inflate (R.menu.main, menu); -         return true; -     } -  in @Override -      Public Booleanonoptionsitemselected (MenuItem item) { to         //Handle Action Bar item clicks here. The Action Bar would +         //automatically handle clicks on the Home/up button, so long -         //As you specify a the parent activity in Androidmanifest.xml. the         intID =Item.getitemid (); *         if(id = =r.id.action_settings) { $             return true;Panax Notoginseng         } -         return Super. onoptionsitemselected (item); the     } +  A @Override the      Public voidOnClick (View v) { +         Switch(V.getid ()) { -          CaseR.id.send_notice: $Notificationmanager manger=(Notificationmanager) Getsystemservice (notification_service); $Notification notification=NewNotification (R.drawable.ic_launcher, "This is ticker text", System.currenttimemillis ()); -Intent intent=NewIntent ( This, Secondactivity.class); -Pendingintent pi=pendingintent.getactivity ( This, 0, intent, pendingintent.flag_cancel_current); theNotification.setlatesteventinfo ( This, "This is the content title", "This is content text", pi); -Manger.notify (1, notification);Wuyi              Break; the  -         default: Wu              Break; -         } About          $     } - } -  -  Public classSecondactivityextendsbaseactivity { A @Override +     protected voidonCreate (Bundle savedinstancestate) { the         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.second); $Notificationmanager manager=(Notificationmanager) Getsystemservice (notification_service); theManager.cancel (1); the     } the}

Android Learning Notification

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.