冲刺八
handler
创建handler
private final Handler handler=new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case msg:
showDialog(REGISTERATION_ACCOUNT_FAILURE);
break;
}
};
};
在调用处调用 发送消息
Message msg= Message.obtain();
msg.what = msg;
handler.sendMessage(msg);
Notification
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
//创建大图标的Bitmap
LargeBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.iv_lc_icon);
mNManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
bindView();
}
private void bindView() {
btn_show_normal = (Button) findViewById(R.id.btn_show_normal);
btn_close_normal = (Button) findViewById(R.id.btn_close_normal);
btn_show_normal.setOnClickListener(this);
btn_close_normal.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_show_normal:
//定义一个PendingIntent点击Notification后启动一个Activity
Intent it = new Intent(mContext, OtherActivity.class);
PendingIntent pit = PendingIntent.getActivity(mContext, 0, it, 0);
//设置图片,通知标题,发送时间,提示方式等属性
Notification.Builder mBuilder = new Notification.Builder(this);
mBuilder.setContentTitle("叶良辰") //标题
.setContentText("我有一百种方法让你呆不下去~") //内容
.setSubText("——记住我叫叶良辰") //内容下面的一小段文字
.setTicker("收到叶良辰发送过来的信息~") //收到信息后状态栏显示的文字信息
.setWhen(System.currentTimeMillis()) //设置通知时间
.setSmallIcon(R