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