安卓學習notification

來源:互聯網
上載者:User

標籤:

 1 寫一個基類activity讓其他的繼承可以顯示的知道哪個活動 2 public class BaseActivity extends Activity { 3     @Override 4     protected void onCreate(Bundle savedInstanceState) { 5         // TODO Auto-generated method stub 6         super.onCreate(savedInstanceState); 7         Log.d("BaseActivity", getClass().getSimpleName()); 8     } 9 }10 11 public class MainActivity extends BaseActivity implements OnClickListener{12     private Button sendbtn;13     @Override14     protected void onCreate(Bundle savedInstanceState) {15         super.onCreate(savedInstanceState);16         setContentView(R.layout.activity_main);17         sendbtn=(Button)findViewById(R.id.send_notice);18         sendbtn.setOnClickListener(this);19         20     }21 22     @Override23     public boolean onCreateOptionsMenu(Menu menu) {24         // Inflate the menu; this adds items to the action bar if it is present.25         getMenuInflater().inflate(R.menu.main, menu);26         return true;27     }28 29     @Override30     public boolean onOptionsItemSelected(MenuItem item) {31         // Handle action bar item clicks here. The action bar will32         // automatically handle clicks on the Home/Up button, so long33         // as you specify a parent activity in AndroidManifest.xml.34         int id = item.getItemId();35         if (id == R.id.action_settings) {36             return true;37         }38         return super.onOptionsItemSelected(item);39     }40 41     @Override42     public void onClick(View v) {43         switch (v.getId()) {44         case R.id.send_notice:45             NotificationManager manger=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);46             Notification notification=new Notification(R.drawable.ic_launcher,"this is ticker text",System.currentTimeMillis());47             Intent intent=new Intent(this,SecondActivity.class);48             PendingIntent pi=PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);49             notification.setLatestEventInfo(this, "this is content title", "this is content text", pi);50             manger.notify(1, notification);51             break;52 53         default:54             break;55         }56         57     }58 }59 60 public class SecondActivity extends BaseActivity {61     @Override62     protected void onCreate(Bundle savedInstanceState) {63         super.onCreate(savedInstanceState);64         setContentView(R.layout.second);65         NotificationManager manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);66         manager.cancel(1);67     }68 }

 

安卓學習notification

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.