zoukankan      html  css  js  c++  java
  • 安卓学习notification

     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     @Override
    14     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     @Override
    23     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     @Override
    30     public boolean onOptionsItemSelected(MenuItem item) {
    31         // Handle action bar item clicks here. The action bar will
    32         // automatically handle clicks on the Home/Up button, so long
    33         // 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     @Override
    42     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     @Override
    62     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 }
  • 相关阅读:
    Android学习 反编译APK文件
    全面剖析C#之String对象
    Retrieving the COM class factory for component with CLSID {0006F03A00000000C000000000000046} failed due to the following error: 80080005
    面向对象的函数式编程语言Scala 简介安装
    Export/Import相关操作
    Windows Server 2008 R2(64位)下安装SQL Server 2005
    C#操作FTP总结
    Windows Server 2008 R2(64位)下IIS7.5操作
    Quartz.Net 学习随手记之01 初步介绍
    差分约束系统
  • 原文地址:https://www.cnblogs.com/oldcownotGiveup/p/5418765.html
Copyright © 2011-2022 走看看